DreamsCoder.com

We Code your Dreams
home > data-structure programs

Dynamic Queue program using C++





Dynamic Queue program using C++

/*
Title - Dynamic Queue program
Author - Chinmay Mahajan 
*/
#include
#include
#include

class dqueue
{
	struct node
	{
		int data;
		node *next;

	}*front,*rear,*temp;
	public: dqueue()
		{
		front=NULL;
		rear=NULL;
		}
		void add();
		void del();
		void display();
};
void dqueue::add()
{
	temp=new node();

	cout<<"Enter the Data \t";
	cin>>temp->data;

	if(front==NULL)
	{
		front=temp;
		rear=temp;
	}
	else
	{
	temp->next=NULL;
	rear->next=temp;
	rear=temp;

	}


} //add()

void dqueue::del()
{
temp=new node();
temp=front;
if(front==NULL)
{
cout<<"No Data Found";
}
else
{
front=front->next;
delete temp;
cout<<"Deleted Successfully";
}//else
}//delete

void dqueue::display()
{
	temp=new node();
	temp=front;

	while(temp!=NULL)
	{
		cout<data;
		temp=temp->next;
	}
}
void main()
{
	clrscr();
	dqueue d;
	int ch;
	do
	{
	cout<<"\n1.Insert\n2.Delete\n3.Display
\n4.Exit\t";
	cin>>ch;
	switch(ch)
	{
	case 1:d.add();
		break;
       case 2:d.del();
		break;
	case 3:d.display();
		break;
	case 4: exit(0);
	default: cout<<"Incorrect Input";
	}
       }while(ch!=4);

}

Label - data-structure





Dynamic Stack program using C++





Dynamic Stack program using C++

/*
Title - Dynamic Stack program
Author - Chinmay Mahajan 
*/
#include
#include
#include

class dstack
{
	private:
		struct node
		{
		int data;
		node *next;
		}*top,*temp;
       public:
		dstack()
		{
		top=NULL;
		}
		void push();
		void pop();
		void display();
};

void dstack::push()
{
temp=new node();
cout<<"\nEnter the data\t";
cin>>temp->data;

	temp->next=top;
   	top=temp;

}

void dstack::pop()
{
temp=new node();
temp=top;
top=top->next;
delete temp;
cout<<"Deleted";
}

void dstack::display()
{
temp=new node();
temp=top;
	while(temp!=NULL)
	{
	cout<<" "<data;
	temp=temp->next;
	}
}//display

void main()
{
clrscr();
dstack s;
int ch;
do
{
cout<<"\n1.PUSH\n2.POP\n3.Display\n4.Exit\n";
cout<<"Enter Your Choice :\t";
cin>>ch;
	switch(ch)
	{
	case 1:s.push();
		break;
	case 2:s.pop();
		break;
	case 3:s.display();
		break;
	case 4:exit(0);
	default : cout<<"Wrong Input";
	}
 }while(ch!=4);
}

Label - data-structure





< previous page | next page>






Privacy Policy
Copyright © 2018 by DreamsCoder. All Rights Reserved.
DreamsCoder Google Plus DreamsCoder Facebook



Latest Technology,Tricks and Tips