Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <windows.h>
- #include <string.h>
- #define SIZE 20
- struct fifo_node{
- char transport[SIZE], z[SIZE], doo[SIZE];
- struct fifo_node *next, *prev;;
- };
- struct fifo_pointers{
- struct fifo_node *head, *tail;
- }fifo;
- void print_queue(struct fifo_pointers fifo)
- {
- while(fifo.head) {
- if(fifo.head->prev==NULL)
- {
- printf("%s",fifo.head->z);
- }
- printf(".%s",fifo.head->transport);
- printf("->%s",fifo.head->doo);
- fifo.head = fifo.head->next;
- }
- puts("");
- }
- void enqueue(struct fifo_pointers *fifo, char *tab, char *tab2, char *tab3)
- {
- struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
- if(new_node) {
- strncpy(new_node->transport, tab, SIZE);
- strncpy(new_node->doo, tab3, SIZE);
- new_node->next = NULL;
- if(fifo->head==NULL)
- {
- new_node->prev = NULL;
- fifo->head = new_node;
- strncpy(new_node->z, tab2, SIZE);
- fifo->tail = new_node;
- }
- else {
- new_node->prev = fifo->tail;
- fifo->tail->next=new_node;
- fifo->tail=new_node;
- fifo->tail->next=NULL;
- }
- } else
- fprintf(stderr,"Nowy element nie został utworzony!\n");
- }
- int main()
- {
- int option=-1;
- int i;
- char tab[SIZE], tab2[SIZE], tab3[SIZE];
- tab2[0]=NULL;
- while(option!=0)
- {
- system("cls");
- printf("Aktualny stan kolejki: ");
- print_queue(fifo);
- printf("\nCo chcesz zrobic?\n");
- printf("1. Dodac element podrozy na koniec kolejki.\n");
- printf("0. Zakonczyc program.\n");
- for(i=0;i<SIZE;i++)
- {
- tab[i]=NULL;
- tab2[i+1]=NULL;
- tab3[i]=NULL;
- }
- scanf("%i", &option);
- switch (option)
- {
- case 0:
- return 0;
- break;
- case 1:
- printf("Wpisz transport jakim bedziesz jechal: ");
- scanf("%s", tab);
- if(tab2[0]==NULL)
- {
- printf("Wpisz miejsce z jakiego bedziesz wyjezdzal: ");
- scanf("%s", tab2);
- }
- printf("Wpisz miejsce do jakiego chcesz dojechac: ");
- scanf("%s", tab3);
- enqueue(&fifo, tab, tab2, tab3);
- break;
- default:
- printf("Podaj wlasciwa opcje."); Sleep(2000);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement