Skip to main content

The Fundamentals of Digital Marketing Certification

The Fundamentals of Digital Marketing Certification
Trying to make use of some spare time during these endless lockdowns. I completed The Fundamentals of Digital Marketing course on Google Digital Garage and got certified. This is not a great victory, nevertheless, I celebrate every small step towards a greater goal. #googlegarage #fundamentalsofdigitalmarketing #digitalmarketing

FDS 12

 Practical No: -12

Experiment No. 12: A double-ended queue(deque) is a linear list in which additions and deletions

may be made at either end. Obtain a data representation mapping a deque into a one-dimensional

array. Write C++ program to simulate deque with functions to add and delete elements from either

end of the deque.

Code:

using namespace std;

#include<iostream>

#include<stdio.h>

#include<process.h>

#define MAX 30

typedef struct dequeue

{

 int data[MAX];

 int rear,front;

}dequeue;

void initialize(dequeue *p);

int isEmpty(dequeue *p);

int isFull(dequeue *p);

void enqueueRear(dequeue *p,int x);

void enqueueFront(dequeue *p,int x);

int dequeueFront(dequeue *p);

int dequeueRear(dequeue *p);

void display(dequeue *p);

main()

{

 int i,x,choice,n;

 dequeue q;

 initialize(&q);

 do

 {

 cout<<"\n 1.Create \n 2.Insert(rear) \n 3.Insert(front) \n 4.Delete(rear) \n 5.Delete(front)";

 cout<<"\n 6.Display \n 7.Exit \n\n Enter your choice:";

 cin>>choice;


 switch(choice)

 {

 case 1:

 cout<<"\n Enter number of elements:";

 cin>>n;

 initialize(&q);

 cout<<"\n Enter the elements:";


 for(i=0;i<n;i++)

 {

 cin>>x;

 if(isFull(&q))

 {

 cout<<"\n Queue is full!!\n";

 exit(0);

 }

 enqueueRear(&q,x);

 }

 break;


 case 2:

 cout<<"\n Enter element to be inserted:\n";

 cin>>x;


 if(isFull(&q))

 {

 cout<<"\n Queue is full!!\n";

 exit(0);

 }


 enqueueRear(&q,x);

 break;


 case 3:

 cout<<"\n Enter the element to be inserted:\n";

 cin>>x;


 if(isFull(&q))

 {

 cout<<"\n Queue is full!!\n";

 exit(0);

 }


 enqueueFront(&q,x);

 break;


 case 4:

 if(isEmpty(&q))

 {

 cout<<"\n Queue is empty!!\n";

 exit(0);

 }


 x=dequeueRear(&q);

 cout<<"\n Element deleted is:\n"<<x;

 break;


 case 5:

 if(isEmpty(&q))

 {

 cout<<"\n Queue is empty!!\n";

 exit(0);

 }


 x=dequeueFront(&q);

 cout<<"\n Element deleted is:\n"<<x;

 break;


 case 6:

 display(&q);

 break;


 default:

 break;

 }

 }

 while(choice!=7);

}

void initialize(dequeue *P)

{

 P->rear=-1;

 P->front=-1;

}

int isEmpty(dequeue *P)

{

 if(P->rear==-1)

 return(1);

 return(0);

}

int isFull(dequeue *P)

{

 if((P->rear+1)%MAX==P->front)

 return(1);

 return(0);

}

void enqueueRear(dequeue *P,int x)

{

 if(isEmpty(P))

 {

 P->rear=0;

 P->front=0;

 P->data[0]=x;

 }


 else

 {

 P->rear=(P->rear+1)%MAX;

 P->data[P->rear]=x;

 }

}

void enqueueFront(dequeue *P,int x)

{

 if(isEmpty(P))

 {

 P->rear=0;

 P->front=0;

 P->data[0]=x;

 }

 else

 {

 P->front=(P->front-1+MAX)%MAX;

 P->data[P->front]=x;

 }

}

int dequeueFront(dequeue *P)

{

 int x;

 x=P->data[P->front];

 if(P->rear==P->front)

 initialize(P);

 else

 P->front=(P->front+1)%MAX;

 return(x);

}

int dequeueRear(dequeue *P)

{

 int x;

 x=P->data[P->rear];

 if(P->rear==P->front)

 initialize(P);


 else

 P->rear=(P->rear-1+MAX)%MAX;

 return(x);

}

void display(dequeue *P)

{

 if(isEmpty(P))

 {

 cout<<"\n Queue is empty!!";

 exit(0);

 }


 int i;

 i=P->front;


 while(i!=P->rear)

 {

 cout<<" "<<P->data[i];

 i=(i+1)%MAX;

 }

 cout<<" "<<P->data[P->rear];

}

GALLERY

GALLERY
photos

ABOUT

HTML CSS, VB.net Developer and Java, C programming. With Loves Problem Solving and to Unreval the Mysteries behind the Magic of Computer Programming

Followers

MY PROJECTS

Popular posts from this blog

dsa

 https://drive.google.com/drive/folders/1xaWUPlioGjpK0WAmAD-mvlxAuA8eTK1c https://github.com/khan0003-py/SPPU-Computer-4th-Sem-Lab-Codes/tree/master/DSAL

FDS 11

 Practical No: -11 Experiment No. 11: Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. If the operating system does not use priorities, then the jobs are processed in the order they enter the system. Write C++ program for simulating job queue. Write functions add job and delete job from queue. Code: using namespace std; #include<iostream> #include<stdio.h> #include<conio.h> #include<stdlib.h> #define SIZE 5 void enqueue(int x); void dequeue(); void display(); int FRONT=-1; int REAR=-1; int QUEUE[SIZE]; main() {  int x,ch;  while(1)  {  cout<<"\n 1:Add Job";  cout<<"\n 2:Delete Job";  cout<<"\n 3:Display";  cout<<"\n 4:Exit";  cout<<"\n Enter Your Choice:";  cin>>ch;  switch(ch)  {  case 1:  cout<<"Enter Job:";  cin>>x;  enqueue(x);  break;  case 2: ...

Contact us

Name

Email *

Message *