.


:




:

































 

 

 

 


5




. 볺 , : 볺 . , : , , , 볺. , , , , , .

 

1. . , , , ( ) . FIFO, . , , :

struct list

{ char* surname;

char* id_cod;

list* next;

};

. ³ , : , , ( ) - . , LIFO, . , - :

struct katalog

{

char bukva;

list* first;

katalog* prev;

};

2. .

: add_kat() - , add_list() .

 

// -

katalog* add_kat(katalog* head, char c)

// head , c , , // -

{katalog* temp=new katalog; // ,
// temp

if(!temp) { cout<<"\n Error of memory";

exit(1); //
//

}

temp->bukva=c; // c bukva
//
temp

temp->first=NULL; //
//

temp->prev=head; // .

// prev temp

return temp; // , return

// -

}

 

//

list* add_list(char* surn, char* idc, list* first)

{ list* temp;

if (!first) {first=new list; temp=first;} // first ,

// ' ,

// first temp. //

else //

{ list* new_list=new list; // '

//

temp=first; // temp

while (temp->next) temp=temp->next; //

//

temp->next=new_list; // next

// . //

temp=new_list; // temp

}

temp->next=NULL; // //

temp->surname=new char[strlen(surn)+1]; // ' //

strcpy(temp->surname, surn); // surname

temp->id_cod=new char[strlen(idc)+1]; // ' .

strcpy(temp->id_cod, idc); // . id_cod

return first; //

}

3. .

print():

void print(katalog* head)

{ katalog* temp=head;

list* ptr;

while (temp) // catalog //

{ptr=temp->first; // ptr //

cout<<"\n\n char "<<temp->bukva; // . //

while (ptr) // ptr

//

{cout<<"\n"<<ptr->surname<<"\t"<<ptr->id_cod; //

ptr=ptr->next; //

}

temp=temp->prev; // -

}

}

4. , .

#include <iostream.h>

#include <conio.h>

#include <string.h>

#include <process.h>

struct list

{ char* surname;

char* id_cod;

list* next;

};

struct katalog

{

char bukva;

list* first;

katalog* prev;

};

katalog* add_kat(katalog*,char);

list* add_list(char*,char*,list*);

void print(katalog*);

void main()

{clrscr();

char ans='y',bukv;

katalog* head=NULL, *kat_ptr;

list* ptr;

char Surn[20], Idc[20];

do

{cout<<"\n input data? "; //

cin>>ans;

if (ans=='n') cout<<"\nend of input";

else

{

cin.ignore(1);

cout<<"\ninput surname\t";

cin.getline(Surn,20); //

cout<<"\ninput ID_Cod\t";

cin.getline(Idc,20); // .

kat_ptr=head; ptr=NULL;

while (kat_ptr)

{ if (kat_ptr->bukva==Surn[0]) {ptr=kat_ptr->first; break;}

kat_ptr=kat_ptr->prev;

} //

// // ptr

if (ptr) add_list(Surn,Idc,ptr); // //

else // -

{head=add_kat(head,Surn[0]); //

// , head -

head->first=add_list(Surn,Idc,NULL); // //, . // head->first

}

}

}

while(ans!='n');

print(head);

getch();

}

add_kat(katalog*,char), add_list(char*,char*,list*) print(katalog*), , .

 





:


: 2016-07-29; !; : 374 |


:

:

, , 1:10
==> ...

1923 - | 1822 -


© 2015-2024 lektsii.org - -

: 0.026 .