# Thread: What are steps to create queue with linked list

1. ## What are steps to create queue with linked list

What are the steps to create queue with linked list

Step 1 : Create a new node
Step 2 : Assign data to the data member of new node
step 2 : if queue is empty go to step 3 else go to step 4
step 3 : Make new node as front
step 4 : Make temporary node as front until it reaches the last node bump the temporary node
step 5 : make temporary node link as new node
step 6 : end

Code:
``` struct QNode {     int key;
struct QNode* next;
};```
How to make function for enqueueig ?

2. You just need a linked list for which you keep track of both the head and the tail. To enqueue is to append a new node at the tail; to dequeue is to retrieve and remove the node at the head.

3. Originally Posted by laserlight
You just need a linked list for which you keep track of both the head and the tail. To enqueue is to append a new node at the tail; to dequeue is to retrieve and remove the node at the head.
okay
This is linked list that can add new node
Code:
```#include<stdio.h>#include<stdlib.h>

struct node{
int Number;
struct node *next;
};

struct node* newNode(int number, struct node *next) {
struct node *new = malloc(sizeof(*new));
new->Number = number;
new->next = next;
return new;
}

void show(struct node *head){
struct node *c;
c = head;
while (c!=NULL){
printf("%d\n",c->Number);
c = c->next;
}

}

int main (void ) {
struct node *head = NULL;

head = newNode(10, head);
head = newNode(20, head);
head = newNode(30, head);

show(head);

return 0;
}```
30
20
10

4. That's also a linked list that prepends to the head, which is not what I'm talking about, unless you want to invert it and say to enqueue to prepend to the head, and to dequeue is to retrieve and remove from the tail. It's up to you.

If you really really don't want to keep track of the tail, go ahead, but then that means that instead of taking constant time, either enqueue or dequeue must take linear time.

5. Originally Posted by laserlight
That's also a linked list that prepends to the head, which is not what I'm talking about, unless you want to invert it and say to enqueue to prepend to the head, and to dequeue is to retrieve and remove from the tail. It's up to you.

If you really really don't want to keep track of the tail, go ahead, but then that means that instead of taking constant time, either enqueue or dequeue must take linear time.
What do you mean ?Can you give pseudo code

Two pointers called
FRONT and REAR are used to keep track of the first and last elements in the queue.

6. Originally Posted by vajra11
What do you mean ?Can you give pseudo code
What do I mean concerning what?

Originally Posted by vajra11
Two pointers called FRONT and REAR are used to keep track of the first and last elements in the queue.
That's head and tail by different names, so refer to my post #2.

Popular pages Recent additions