SHARE
TWEET

Untitled

a guest Dec 7th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct QNode {
  2.     char* line;//char line[100];
  3.     struct QNode* next;
  4. };
  5.  
  6. // The queue, front stores the front node of LL and rear stores the
  7. // last node of LL
  8. struct Queue {
  9.     struct QNode *front, *rear;
  10.     omp_lock_t lock;
  11.     int enqueued;
  12.     int dequeued;
  13. };
  14.  
  15. // A utility function to create a new linked list node.
  16. struct QNode* newNode(char* newLine) {
  17.     struct QNode* temp = malloc(sizeof(struct QNode));
  18.     temp->line = malloc(strlen (newLine) + 1);
  19.     strcpy(temp->line, newLine);
  20.     temp -> next = NULL;
  21.     return temp;
  22. }
  23.  
  24. // A utility function to create an empty queue
  25. struct Queue* createQueue() {
  26.     struct Queue* q = malloc(sizeof(struct Queue));
  27.     q -> enqueued = q -> dequeued = 0;
  28.     omp_init_lock(&q->lock);
  29.     q -> front = q -> rear = NULL;
  30.     return q;
  31. }
  32.  
  33. //enQueue to add a new line into the queue
  34. void enQueue(struct Queue* q, char newString[]) {
  35.     // Create a new LL node
  36.     struct QNode* temp = newNode(newString);
  37.  
  38.     // If queue is empty, then new node is front and rear both
  39.     if (q->rear == NULL) {
  40.         q->front = q->rear = temp;
  41.         return;
  42.     }
  43.  
  44.     // Add the new node at the end of queue and change rear
  45.     q->rear->next = temp;
  46.     q->rear = temp;
  47. }
  48.  
  49. // Function to remove a key from given queue q
  50. struct QNode* deQueue(struct Queue* q) {
  51.     // If queue is empty, return NULL.
  52.     if (q->front == NULL)
  53.         return NULL;
  54.  
  55.     // Store previous front and move front one node ahead
  56.     struct QNode* temp = q->front;
  57.     //free(temp);
  58.  
  59.     q->front = q->front->next;
  60.  
  61.     // If front becomes NULL, then change rear also as NULL
  62.     if (q->front == NULL)
  63.         q->rear = NULL;
  64.     return temp;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top