Advertisement
palmerstone

Linked List

Sep 11th, 2011
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. struct node
  8. {
  9.     int x;
  10.     node *ptr;
  11. };
  12.  
  13. node *ptr2, *ptr3;
  14.  
  15. int main()
  16. {
  17.     int t, i, j, k, l, a, b, c, d, y, z, n;
  18.     char ch;
  19.  
  20.     ptr2 = 0, ptr3 = 0;
  21.     ptr2 = (node *)malloc(sizeof(node));
  22.     ptr2->ptr = 0;
  23.     ptr3 = ptr2;
  24.     ptr2->x = 10;
  25.  
  26.  
  27.     scanf("%d", &t);
  28.     getchar();
  29.     for (i = 1; i <= t; i++)
  30.    {
  31.        ch = getchar();
  32.        if (ch == 100)
  33.        {
  34.            if (ptr3->ptr == 0) puts("Queue Empty");
  35.             else
  36.             {
  37.                 printf("%d\n", ptr3->x);
  38.                 ptr3 = ptr3->ptr;
  39.                 getchar();
  40.             }
  41.         }
  42.         else
  43.         {
  44.             scanf("%d", &d);
  45.             ptr2->ptr = (node *)malloc(sizeof(node));
  46.             ptr2->x = d;
  47.             ptr2 = ptr2->ptr;
  48.             ptr2->ptr = 0;
  49.             getchar();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement