answersLogoWhite

0


Best Answer

Write a C program for Dequeue

#include

#include

struct dll

{

struct dll *llink;

int data;

struct dll *rlink;

};

typedef struct dll node;

node *first=NULL, *new;

void create(),insertbeg(),insertmid(),insertend(),insert();

void delbeg(),delmid(),delend(),delete();

void display();

void main()

{

char ch='y';

int c;

clrscr();

while(ch=='y')

{

printf("1. create 2. insert 3. delete 4. display 5.exit\n");

printf("enter u'r choice");

scanf("%d",&c);

switch(c)

{

case 1: create();break;

case 2: insert();break;

case 3: delete();break;

case 4: display();

}

printf("do u want to continue(y/n)");

fflush(stdin);

scanf("%c",&ch);

}

}

void create()

{

node *temp;

char ch='y';

temp=first;

do

{

printf("enter the data for new node\n");

new=(node *)malloc(sizeof(node));

scanf("%d",&new->data);

if(first==NULL)

{

first=new;

temp=new;

new->llink=NULL;

new->rlink=NULL;

}

else

{

temp->rlink=new;

new->llink=temp;

new->rlink=NULL;

temp=new;

}

printf("do u wnat to create another node(y/n)");

ch=getchar();

fflush(stdin);

}while(ch!='n');

}

void insert()

{

char ch='y';

int c;

while(ch=='y')

{

printf("1.insertbeg 2: insertmid 3. insertend 4. exit\n");

printf("enter u'r option");

scanf("%d",&c);

switch(c)

{

case 1:insertbeg();break;

case 2:insertmid();break;

case 3:insertend();

}

printf("do u want to continue(y/n)");

fflush(stdin);

ch=getchar();

}

}

void insertbeg()

{

printf("enter data for node to aded in the beginnning");

new=(node *)malloc(sizeof(node));

scanf("%d",&new->data);

if(first==NULL)

{

first=new;

new->llink=NULL;

new->rlink=NULL;

}

else

{

new->rlink=first;

first->llink=new;

new->llink=NULL;

first=new;

}

}

void insertmid()

{

int pos,i=1;

node *temp;

temp=first;

printf("enter the positon to insert a node");

scanf("%d",&pos);

printf("enter data for node to be added at a positon %d",pos);

new=(node *)malloc(sizeof(node));

scanf("%d",&new->data);

while(i {

temp=temp->rlink;

i++;

}

temp->rlink->llink=new;

new->rlink=temp->rlink;

temp->rlink=new;

new->llink=temp;

}

void insertend()

{

node *temp;

temp=first;

printf("enter data for node to be aded at end");

new=(node *)malloc(sizeof(node));

scanf("%d",&new->data);

while(temp->rlink!=NULL)

{

temp=temp->rlink;

}

temp->rlink=new;

new->llink=temp;

new->rlink=NULL;

}

void delete()

{

char ch='y';

int c;

while(ch=='y')

{

printf("1. delbeg 2. delmid 3. delend 4. exit\n");

printf("enter u'r option");

scanf("%D",&c);

switch(c)

{

case 1: delbeg();break;

case 2: delmid();break;

case 3: delend();break;

}

printf("do u want to continue(y/n)");

ch=getchar();

}

}

void delbeg()

{

node *temp;

if(first==NULL)

{

printf("deletion not possible");

exit();

}

else

{

first=first->rlink;

first->llink=NULL;

}

}

void delmid()

{

int pos,i=1;

node *temp;

temp=first;

printf("enter the position to delete a node");

scanf("%d",&pos);

while(i {

temp=temp->rlink;

i++;

}

temp->rlink->rlink->llink=temp;

temp->rlink=temp->rlink->rlink;

}

void delend()

{

node * temp;

temp=first;

while(temp->rlink->rlink!=NULL)

{

temp=temp->rlink;

}

temp->rlink->llink=NULL;

temp->rlink=NULL;

}

void display()

{

node *temp;

if(first==NULL)

{

printf("linked list is empty");

exit();

}

else

{

printf("the contents of dd are :\n");

temp=first;

while(temp->rlink!=NULL)

{

printf("%d",temp->data);

temp=temp->rlink;

}

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

write a program by using queue for together two queue?

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to implement dequeue?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program of binary heap in c or c language?

to implement operations on binary heap in c


Write a program in c language to implement framing methods like character stuffing?

A program in c language to implement framing methods like character stuffing can be grave sizeCRC-32 and the variable c50.


Write a program in c plus plus to implement macro processor?

Don't write, it is already written, google for 'cpp'.


Write a C program to implement excelp system call?

You are not able to do that, but you can write a program, that uses the system-call./* exectest.c */#include int main (void){execlp ("/bin/ls", "ls", "-ld", ".", NULL);return 0;}


Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.


Write a program to convert temperature degrees celsius to degrees fahrenheit?

Here's a full tutorial of how to implement and build the program. Great Stuff! See below


How do you run graphics program in C?

pro c language to implement linear search using pointers


Write a c program for creating a virus?

a c program for creat a virus


C program to implement arithmetic assignment operator?

y=2x2+3x+1


Where do we write main function in a c program?

Into the source program.


Program to delete elements at both ends in a dequeue using c plus plus?

#include<deque> std::deque<int> deq; deq.push_back (42); deq.pop_back (); deq.push_front (0); deq.pop_front ();


Write a c program to find Volume and surface area of cube?

Write a c program to compute the surface area and volume of a cube