Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Linked List Implementation of Queue in C

1,228

Published on

Published in: Technology, Business
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total Views
1,228
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
16
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. /*Linked List Implementation of the Queue in CAuthor: Kasun Ranga WijeweeraEmail: krw19870829@gmail.comDate: 20130514*/#include<stdio.h>#include<conio.h>#include<alloc.h>typedef struct queueNode *link;struct queueNode{int data;link next;};typedef struct{link front;link rear;}queue;
• 2. void initQueue(queue *q){q->front=NULL;q->rear=NULL;}int isEmpty(queue *q){if((q->front)==NULL){return 0;}else{return 1;}}void putQueue(queue *q,int x){link t=(link)malloc(sizeof(struct queueNode));t->data=x;t->next=NULL;
• 3. if(isEmpty(q)){q->rear->next=t;q->rear=t;}else{q->front=t;q->rear=t;}}int getQueue(queue *q){link t=q->front;int x=t->data;if((q->front)==(q->rear)){q->front=NULL;q->rear=NULL;}else{
• 4. q->front=t->next;}free(t);return x;}void printQueue(queue *q){link t=q->front;while(t!=NULL){printf("%d ",t->data);t=t->next;}}void main(){queue *q;int x;clrscr();
• 5. q=(queue*)malloc(sizeof(queue));initQueue(q);putQueue(q,10);putQueue(q,20);putQueue(q,30);putQueue(q,40);putQueue(q,50);printf("n");printQueue(q);if(isEmpty(q))x=getQueue(q);printf("n");printQueue(q);putQueue(q,60);putQueue(q,70);printf("n");printQueue(q);getch();
• 6. }