Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. typedef struct lista{
  2. int brpasosa;
  3. char ime[20], prezime[20], destinacija[20];
  4. struct lista *sled;
  5. }l;
  6.  
  7. l *prvi=NULL;
  8.  
  9. void dodaj(){
  10. l *novi=(l*)malloc(sizeof(l));
  11. int br;
  12. char name[20], lname[20], des[20];
  13. printf("\nUnesite ime a zatim prezime putnika:\n");
  14. scanf("%s", name);scanf("%s", lname);
  15. printf("Unesite broj pasosa:\n");
  16. scanf("%d", &br);
  17. printf("Unesite destinaciju:\n");
  18. scanf("%s", des);
  19. strcpy(novi->ime, name);
  20. strcpy(novi->prezime, lname);
  21. strcpy(novi->destinacija, des);
  22. novi->brpasosa=br;
  23. novi->sled=NULL;
  24. if(prvi==NULL)
  25. prvi=novi;
  26. else{
  27. l*tek;
  28. l*pr;
  29. for(tek=prvi;tek;tek=tek->sled)
  30. {
  31. if(strcmp(novi->destinacija,tek->destinacija)==0)
  32. {
  33. if(novi->brpasosa<tek->brpasosa)
  34. {
  35. pr=tek;
  36. tek=novi;
  37. novi=pr;
  38. break;
  39. }
  40. }
  41. }
  42. if(tek!=novi){tek->sled=novi;}
  43.  
  44. }
  45. }
  46.  
  47. void prikazi(){
  48. l *tek;
  49. for(tek=prvi;tek;tek=tek->sled)
  50. printf("\nIme i prezime: %s %s\nBr pasosa: %d\nDestinacija: %s\n", tek->ime, tek->prezime, tek->brpasosa, tek->destinacija);
  51. }
  52.  
  53. int main()
  54. {
  55. FILE *fp;
  56. int opcija=0;
  57. do{
  58. printf("1.Dodaj\n2.Prikazi\nUnesite opciju: ");
  59. scanf("%d", &opcija);
  60. switch(opcija){
  61. case 1: dodaj();break;
  62. case 2: prikazi();break;
  63. default:printf("Unesite validnu opciju!");break;
  64. }
  65. }while(1);
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement