Implementation of the ADT interface linked list of the FIFO queue
FIFO. h (Interface)
1 #include "Item.h"
2 void QUEUinit(int);
3 int QUEUempty(void);
4 void QUEUput(Item);
5 Item QUEUget(void);
Item. h (custom type)
1 typedef char Item;
FIFO. c (interface implementation)
1 #include "FIFO.h"
2 #include <stdlib.h>
3
4 typedef struct STACKnode *link;
5 struct STACKnode
6 {
7 Item item;
8 link next;
9 };
10
11 static link head,tail;
12 static int N=1,N1;
13
14 static int STACKerror(int i)
15 {
16 if(i)
17 return N<N1?1:0;
18
19 else
20 return N>0 ?1:0;
21 }
22 link NEW(Item item, link next)
23 {24 link x = malloc(sizeof *x);
25 x->item=item; x->next=next;
26 return x;27 }
28 void QUEUinit(int maxN)
29 {
30 N1=maxN;
31 head=NULL;
32 }
33 int QUEUempty(void)
34 {
35 return N;
36 }
37 void QUEUput(Item item)
38 {
39 if(head==NULL)
40 {
41 head=(tail=NEW(item, head));
42 return ;
43 }
44 tail->next=NEW(item, tail->next);
45 tail=tail->next;
46 N++;
47 }
48 Item QUEUget(void)
49 {
50 if(STACKerror(0))
51 {
52 Item item=head->item;
53 link t=head->next;
54 free(head);head=t;
55 N--;
56 return item;
57 }
58 else
59 printf("\nSTACKpop false");
60 return NULL;
61 }
Main. c (main Program)
1 #include <stdio.h>
2 #include "FIFO.h"
3
4 int main(void)
5 {
6 int N;
7 Item str[11];
8 scanf("%s", str);
9 getchar();
10
11 N=sizeof(str)/sizeof(str[0]);
12 printf("%d\n",N);
13
14 QUEUinit(N);
15 for(int i=0; i<N; i++)
16 {
17 QUEUput(str[i]);
18 }
19 for(int i=0; i<N; i++)
20 {
21 printf("%c",QUEUget());
22 }
23
24 return 0;
25 }