Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct lista{
- int brpasosa;
- char ime[20], prezime[20], destinacija[20];
- struct lista *sled;
- }l;
- l *prvi=NULL;
- void dodaj(){
- l *novi=(l*)malloc(sizeof(l));
- int br;
- char name[20], lname[20], des[20];
- printf("\nUnesite ime a zatim prezime putnika:\n");
- scanf("%s", name);scanf("%s", lname);
- printf("Unesite broj pasosa:\n");
- scanf("%d", &br);
- printf("Unesite destinaciju:\n");
- scanf("%s", des);
- strcpy(novi->ime, name);
- strcpy(novi->prezime, lname);
- strcpy(novi->destinacija, des);
- novi->brpasosa=br;
- novi->sled=NULL;
- if(prvi==NULL)
- prvi=novi;
- else{
- l*tek;
- l*pr;
- for(tek=prvi;tek;tek=tek->sled)
- {
- if(strcmp(novi->destinacija,tek->destinacija)==0)
- {
- if(novi->brpasosa<tek->brpasosa)
- {
- pr=tek;
- tek=novi;
- novi=pr;
- break;
- }
- }
- }
- if(tek!=novi){tek->sled=novi;}
- }
- }
- void prikazi(){
- l *tek;
- for(tek=prvi;tek;tek=tek->sled)
- printf("\nIme i prezime: %s %s\nBr pasosa: %d\nDestinacija: %s\n", tek->ime, tek->prezime, tek->brpasosa, tek->destinacija);
- }
- int main()
- {
- FILE *fp;
- int opcija=0;
- do{
- printf("1.Dodaj\n2.Prikazi\nUnesite opciju: ");
- scanf("%d", &opcija);
- switch(opcija){
- case 1: dodaj();break;
- case 2: prikazi();break;
- default:printf("Unesite validnu opciju!");break;
- }
- }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement