Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include <string.h>
  6.  
  7. #define SIZE 20
  8.  
  9. struct fifo_node{
  10. char transport[SIZE], z[SIZE], doo[SIZE];
  11. struct fifo_node *next, *prev;;
  12. };
  13.  
  14. struct fifo_pointers{
  15. struct fifo_node *head, *tail;
  16. }fifo;
  17.  
  18. void print_queue(struct fifo_pointers fifo)
  19. {
  20. while(fifo.head) {
  21. if(fifo.head->prev==NULL)
  22. {
  23. printf("%s",fifo.head->z);
  24. }
  25. printf(".%s",fifo.head->transport);
  26. printf("->%s",fifo.head->doo);
  27. fifo.head = fifo.head->next;
  28. }
  29. puts("");
  30. }
  31.  
  32. void enqueue(struct fifo_pointers *fifo, char *tab, char *tab2, char *tab3)
  33. {
  34. struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
  35. if(new_node) {
  36. strncpy(new_node->transport, tab, SIZE);
  37. strncpy(new_node->doo, tab3, SIZE);
  38. new_node->next = NULL;
  39. if(fifo->head==NULL)
  40. {
  41. new_node->prev = NULL;
  42. fifo->head = new_node;
  43. strncpy(new_node->z, tab2, SIZE);
  44. fifo->tail = new_node;
  45.  
  46.  
  47. }
  48.  
  49. else {
  50. new_node->prev = fifo->tail;
  51. fifo->tail->next=new_node;
  52. fifo->tail=new_node;
  53. fifo->tail->next=NULL;
  54. }
  55. } else
  56. fprintf(stderr,"Nowy element nie został utworzony!\n");
  57. }
  58.  
  59. int main()
  60. {
  61. int option=-1;
  62. int i;
  63. char tab[SIZE], tab2[SIZE], tab3[SIZE];
  64. tab2[0]=NULL;
  65. while(option!=0)
  66. {
  67. system("cls");
  68. printf("Aktualny stan kolejki: ");
  69. print_queue(fifo);
  70.  
  71. printf("\nCo chcesz zrobic?\n");
  72. printf("1. Dodac element podrozy na koniec kolejki.\n");
  73. printf("0. Zakonczyc program.\n");
  74. for(i=0;i<SIZE;i++)
  75. {
  76. tab[i]=NULL;
  77. tab2[i+1]=NULL;
  78. tab3[i]=NULL;
  79. }
  80. scanf("%i", &option);
  81. switch (option)
  82. {
  83. case 0:
  84. return 0;
  85. break;
  86.  
  87. case 1:
  88. printf("Wpisz transport jakim bedziesz jechal: ");
  89. scanf("%s", tab);
  90. if(tab2[0]==NULL)
  91. {
  92. printf("Wpisz miejsce z jakiego bedziesz wyjezdzal: ");
  93. scanf("%s", tab2);
  94. }
  95. printf("Wpisz miejsce do jakiego chcesz dojechac: ");
  96. scanf("%s", tab3);
  97. enqueue(&fifo, tab, tab2, tab3);
  98. break;
  99.  
  100. default:
  101. printf("Podaj wlasciwa opcje."); Sleep(2000);
  102. break;
  103.  
  104. }
  105.  
  106. }
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement