Advertisement
rafikamal

Queue

Feb 10th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define SIZE 100
  5.  
  6. int queue[SIZE];
  7. int start = 0;
  8. int end = 0;
  9.  
  10. void enqueue(int value);
  11. int dequeue();
  12.  
  13. int main()
  14. {
  15.     enqueue(10);
  16.     enqueue(18);
  17.     printf("%d\n", dequeue());
  18.     enqueue(12);
  19.     enqueue(4);
  20.     printf("%d\n", dequeue());
  21.     printf("%d\n", dequeue());
  22.     printf("%d\n", dequeue());
  23.    
  24.     return 0;
  25. }
  26.  
  27. void enqueue(int value)
  28. {
  29.     if(end == SIZE)
  30.     {
  31.         printf("Queue Full\n");
  32.         exit(1);
  33.     }
  34.     queue[end++] = value;
  35. }
  36.  
  37. int dequeue()
  38. {
  39.     if(start == end)
  40.     {
  41.         printf("Queue Empty\n");
  42.         exit(2);
  43.     }
  44.     return queue[start++];
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement