0% found this document useful (0 votes)
2 views5 pages

Dequeue

The document contains C code for implementing a circular queue and a doubly linked list. The circular queue allows for enqueueing and dequeueing elements with checks for full and empty conditions, while the doubly linked list supports insertion and deletion from both ends. Both data structures include display functions to show their current contents.

Uploaded by

jiyakandpal728
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Dequeue

The document contains C code for implementing a circular queue and a doubly linked list. The circular queue allows for enqueueing and dequeueing elements with checks for full and empty conditions, while the doubly linked list supports insertion and deletion from both ends. Both data structures include display functions to show their current contents.

Uploaded by

jiyakandpal728
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Ques- Circular Link list

#include<stdio.h>

#define MAX 5

int cq[MAX];

int front = -1, rear = -1;

void enqueue()

int x;

if((rear+1)%MAX == front) {

printf("Queue is Full\n");

return; }

printf("Enter element: ");

scanf("%d",&x);

if(front == -1 && rear == -1) {

front = rear = 0; }

else {

rear = (rear + 1) % MAX; }

cq[rear] = x;

void dequeue(){

if(front == -1) {

printf("Queue is Empty\n");

return; }

printf("Deleted element = %d\n", cq[front]);

if(front == rear){

front = rear = -1; }

else

front = (front + 1) % MAX;


}

void display(){

int i;

if(front == -1) {

printf("Queue is Empty\n");

return; }

printf("Queue elements: ");

i = front;

while(i != rear) {

printf("%d ", cq[i]);

i = (i + 1) % MAX; }

printf("%d\n", cq[rear]);

}
Ques- Double link list
#include<stdio.h>

#include<stdlib.h>

struct node

int data;

struct node *prev;

struct node *next;

};

struct node *head=NULL,*temp,*newnode;

void insert_left(){

int x;

printf("Enter value: ");

scanf("%d",&x);

newnode=(struct node*)malloc(sizeof(struct node));

newnode->data=x;

newnode->prev=NULL;

newnode->next=head;

if(head!=NULL)

head->prev=newnode;

head=newnode;}

void insert_right(){

int x;

printf("Enter value: ");

scanf("%d",&x);

newnode=(struct node*)malloc(sizeof(struct node));

newnode->data=x;

newnode->next=NULL;
if(head==NULL) {

newnode->prev=NULL;

head=newnode; }

else{

temp=head;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newnode;

newnode->prev=temp; }}

void delete_left(){

if(head==NULL) {

printf("List is empty\n");

return; }

temp=head;

head=head->next;

if(head!=NULL)

head->prev=NULL;

printf("Deleted element = %d\n",temp->data);

free(temp);}

void delete_right(){

if(head==NULL) {

printf("List is empty\n");

return; }

temp=head;

while(temp->next!=NULL)

temp=temp->next;

if(temp->prev!=NULL)

temp->prev->next=NULL;

else

head=NULL;
printf("Deleted element = %d\n",temp->data);

free(temp);}

void display(){

temp=head;

if(temp==NULL) {

printf("List is empty\n");

return;}

printf("List: ");

while(temp!=NULL) {

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

temp=temp->next; }

printf("NULL\n"); }

You might also like