Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include "queue.h"
  2.  
  3. Node_line *CreateNode(int x){
  4.     Node_line *aux = (Node_line*) malloc(sizeof(Node_line));
  5.     aux->data = x;
  6.     aux->next = NULL;
  7.     return aux;
  8. }
  9.  
  10.  
  11. Queue *lnCreate(){
  12.     Queue *temp = (Queue*) malloc(sizeof(Queue));
  13.     temp->begin = NULL;
  14.     temp->begin = NULL;
  15.     return temp;
  16. }
  17.  
  18. void lnDestroy(Queue *p){
  19.     if (p->begin != NULL){
  20.         lnPop(p);
  21.         lnDestroy(p);
  22.     }
  23. }
  24.  
  25. int lnIsEmpty(Queue *p){
  26.     if (p->begin == NULL){
  27.         return True;
  28.     } return False;
  29. }
  30.  
  31. void lnPrint(Queue *p){
  32.     Node_line *temp1 = p->begin;
  33.     while (temp1 != NULL) {
  34.         if (temp1->next == NULL){
  35.             printf("[%i]->NULL\n", temp1->data);
  36.         } else {
  37.             printf("[%i]->", temp1->data);
  38.         }
  39.         temp1 = temp1->next;  
  40.     }
  41. }
  42.  
  43. void lnPush(Queue *p, int x){
  44.     Node_line *temp = CreateNode(x);
  45.     if (lnIsEmpty(p) == True){
  46.         p->begin = temp;
  47.     }
  48.     p->end->next = temp;
  49.     p->end = temp;
  50. }
  51.  
  52. Type lnPop(Queue *p){
  53.     if (lnIsEmpty(p) == False){
  54.         Node_line *aux = p->begin;
  55.         Type x = aux->data;
  56.         p->begin = aux->next;
  57.         if (p->begin == NULL)
  58.             p->end = NULL;
  59.         free(aux);
  60.         return x;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement