Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct fifo_node
  5. {
  6.     char name[20];
  7.     char surname[20];
  8.     int class;
  9.     char station_A[20];
  10.     char station_B[20];
  11.     int price;
  12.     int data;
  13.     struct fifo_node *next;
  14. };
  15.  
  16. struct fifo_pointers
  17. {
  18.     struct fifo_node *head, *tail;
  19. } fifo;
  20.  
  21. void enqueue(struct fifo_pointers *fifo)
  22. {
  23.     struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
  24.  
  25.     if(new_node)
  26.     {
  27.         new_node->next = NULL;
  28.  
  29.         if(fifo->head==NULL)
  30.             fifo->head = fifo->tail = new_node;
  31.         else {
  32.           fifo->tail->next=new_node;
  33.           fifo->tail=new_node;}
  34.  
  35.         puts("PODAJ IMIE:\n");
  36.         scanf("%s",new_node->name);
  37.  
  38.         puts("PODAJ NAZWISKO:\n");
  39.         scanf("%s",new_node->surname);
  40.  
  41.         do
  42.         {
  43.             printf("Podaj klase (1 lub 2):\n");
  44.             scanf("%d",&new_node->class);
  45.         }while(new_node->class<0 || new_node->class>2);
  46.  
  47.         puts("PODAJ PUNKT POCZATKOWY:\n");
  48.         scanf("%s",new_node->station_A);
  49.  
  50.         puts("PODAJ PUNKT DOCELOWY:\n");
  51.         scanf("%s",new_node->station_B);
  52.     }
  53. }
  54.  
  55. void print_queue(struct fifo_pointers fifo)
  56. {
  57.     while(fifo.head) {
  58.         printf("%d ",fifo.head->data);
  59.         fifo.head = fifo.head->next;
  60.     }
  61.     puts("");
  62. }
  63.  
  64. void print_queue_with_for(struct fifo_pointers fifo)
  65. {
  66.     for(;fifo.head;fifo.head=fifo.head->next)
  67.         printf("%d ",fifo.head->data);
  68.     puts("");
  69. }
  70.  
  71. int main(void)
  72. {
  73.   srand(time(NULL));
  74.     int i,a;
  75.  
  76.        while(1)
  77.          {
  78.              printf("\n\n1. DODAJ OSOBE:\n");
  79.              printf("2. WYSWIETL I USUN CALA KOLEJKE:\n");
  80.              printf("3. WYJSCIE\n");
  81.              scanf("%d",&a);
  82.              if(a==1)
  83.              {
  84.                  enqueue(&fifo);
  85.              }
  86.              if(a==2)
  87.              {
  88.                  while(fifo.head!=NULL)
  89.                  {
  90.                      printf("\n*****************");
  91.                      printf("\nImie pasazera:%s\n",fifo.head->name);
  92.                      printf("Nazwisko pasazera:%s\n",fifo.head->surname);
  93.                      printf("Klasa pociagu:%d\n",fifo.head->class);
  94.                      printf("Punkt poczatkowy:%s\n",fifo.head->station_A);
  95.                      printf("Punkt docelowy:%s\n",fifo.head->station_B);
  96.                      printf("Cena biletu:%lf\n",fifo.head->price);
  97.                      fifo.head=fifo.head->next;
  98.                  }
  99.                  if(fifo.head==NULL && a==2)
  100.                  {
  101.                      printf("\nKolejka pusta");
  102.                  }
  103.                  free(fifo.head);
  104.              }
  105.              if(a==3)
  106.                  return 0;
  107.          }
  108.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement