/*Linked List Implementation of Deque in CAuthor: Kasun Ranga WijeweeraEmail: krw19870829@gmail.comDate: 20130515*/#includ...
void initDeque(deque *d){d->front=NULL;d->rear=NULL;}int isEmpty(deque *d){if((d->front)==NULL){return 0;}else{return 1;}}...
if(isEmpty(d)){t->next=d->front;d->front=t;}else{d->front=t;d->rear=t;}}void putRear(deque *d,int x){link t=(link)malloc(s...
else{d->front=t;d->rear=t;}}int getFront(deque *d){link t=d->front;int x=t->data;if((d->front)==(d->rear)){d->front=NULL;d...
int getRear(deque *d){link t=d->front;link tr=d->rear;int x=tr->data;if(t==tr){d->front=NULL;d->rear=NULL;}else{while((t->...
void printDeque(deque *d){link t=d->front;while(t!=NULL){printf("%d ",t->data);t=t->next;}}void main(){int x;deque *d;clrs...
putRear(d,50);putFront(d,60);printf("n");printDeque(d);if(isEmpty(d))x=getFront(d);printf("n");printDeque(d);if(isEmpty(d)...
}
Upcoming SlideShare
Loading in …5
×

Linked List Implementation of Deque in C

0 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
0
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
71
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linked List Implementation of Deque in C

  1. 1. /*Linked List Implementation of Deque in CAuthor: Kasun Ranga WijeweeraEmail: krw19870829@gmail.comDate: 20130515*/#include<stdio.h>#include<conio.h>#include<alloc.h>typedef struct dequeNode *link;struct dequeNode{int data;link next;};typedef struct{link front;link rear;}deque;
  2. 2. void initDeque(deque *d){d->front=NULL;d->rear=NULL;}int isEmpty(deque *d){if((d->front)==NULL){return 0;}else{return 1;}}void putFront(deque *d,int x){link t=(link)malloc(sizeof(struct dequeNode));t->data=x;t->next=NULL;
  3. 3. if(isEmpty(d)){t->next=d->front;d->front=t;}else{d->front=t;d->rear=t;}}void putRear(deque *d,int x){link t=(link)malloc(sizeof(struct dequeNode));t->data=x;t->next=NULL;if(isEmpty(d)){d->rear->next=t;d->rear=t;}
  4. 4. else{d->front=t;d->rear=t;}}int getFront(deque *d){link t=d->front;int x=t->data;if((d->front)==(d->rear)){d->front=NULL;d->rear=NULL;}else{d->front=t->next;}free(t);return x;}
  5. 5. int getRear(deque *d){link t=d->front;link tr=d->rear;int x=tr->data;if(t==tr){d->front=NULL;d->rear=NULL;}else{while((t->next)!=tr){t=t->next;}d->rear=t;t->next=NULL;}free(tr);return x;}
  6. 6. void printDeque(deque *d){link t=d->front;while(t!=NULL){printf("%d ",t->data);t=t->next;}}void main(){int x;deque *d;clrscr();d=(deque*)malloc(sizeof(deque));initDeque(d);putFront(d,10);putFront(d,20);putRear(d,30);putFront(d,40);
  7. 7. putRear(d,50);putFront(d,60);printf("n");printDeque(d);if(isEmpty(d))x=getFront(d);printf("n");printDeque(d);if(isEmpty(d))x=getRear(d);printf("n");printDeque(d);if(isEmpty(d))x=getFront(d);printf("n");printDeque(d);getch();
  8. 8. }

×