nguyentruong98

Untitled

Dec 1st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct Node
  5. {
  6.       char Name[80], Phone[80], Email[80];
  7.       struct Node *next;
  8. } Node;
  9. typedef struct Queue
  10. {
  11.       struct Node *head;
  12. } Queue;
  13. Node *front(Queue q);
  14. {
  15.       if (q.head == NULL)
  16.             return;
  17.       return q.head;
  18. }
  19. Queue *makeQueue()
  20. {
  21.       Queue *q;
  22.       q = (Queue *)malloc(sizeof(Queue));
  23.       q->head = NULL;
  24.       return q;
  25. }
  26. void pop(Queue *q)
  27. {
  28.       Node *tmp;
  29.       if (q.head == NULL)
  30.       {
  31.             printf("ERROR\n");
  32.             return;
  33.       }
  34.       Node *tmp = q.head;
  35.       q.head = q.head->next;
  36.       free(tmp);
  37. }
  38. void push(Queue *q, Node *node)
  39. {
  40.       Node *iterator;
  41.       if (q.head == NULL)
  42.       {
  43.             q.head = iterator;
  44.             return;
  45.       }
  46.       Node *iterator = q.head;
  47.       while (iterator->next != NULL)
  48.       {
  49.             iterator = iterator->next;
  50.       }
  51.       iterator->next = p;
  52.       return;
  53. }
  54. int main()
  55. {
  56.       Queue *q = makeQueue();
  57.       FILE *f;
  58.       f = fopen("phonebook.txt", "r");
  59.       if (f == NULL)
  60.       {
  61.             printf("ERROR");
  62.       }
  63.       else
  64.       {
  65.             char s1[80], s2[80], s3[80];
  66.             do
  67.             {
  68.                   fscanf(f, "%s %s %s", s1, s2, s3);
  69.                   while (feof(f))
  70.                   {
  71.                         Node *newNode = makeNode(s1, s2, s3);
  72.                         push(q, newNode);
  73.                   }
  74.             }
  75.       }
  76.       Node *node = q.front();
  77.       q.pop();
  78.       while (node != NULL)
  79.       {
  80.             node = q.front();
  81.             q.pop();
  82.       }
  83.       return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment