Your SlideShare is downloading. ×
Linked List Implementation of Queue in C
Upcoming SlideShare
Loading in...5
×

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.
Text the download link to your phone
Standard text messaging rates apply

Linked List Implementation of Queue in C

1,228

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
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. }

×