Vous êtes sur la page 1sur 35

Name shubhada subhash gunjal roll no-13

2)write a program to implement Doubly Linked List in c++ perform all operations.
____________________________________________________________________________________
#include<iostream>
using namespace std;

class DLL{
int data;
DLL *next,*prev;
public:void insert(int i);
void traverse();
}*start=NULL,*n,*temp;

void DLL::insert(int i){


cout<<"Inside INSERT:"<<endl;
n=new DLL();
n->data= i;
n->next=n->prev=NULL;
if(start==NULL)
start=n;
else{
temp=start;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
n->prev=temp;
}
}

void DLL::traverse(){
temp=start;
while(temp->next!=start){
cout<<temp->data<<" -> ";
temp=temp->next;
}
}

int main(){
DLL obj;
cout<<"INSERT:"<<endl;
obj.insert(200);
obj.insert(250);
obj.insert(100);
obj.traverse();
}
Name shubhada subhash gunjal roll no-13

3)write a program to implement Doubly Circular Linked List in C++


____________________________________________________________________________________
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct node
{
int info;
struct node *next;
struct node *prev;
}*start;
class double_llist
{
public:
void create_list(int value);
void add_begin(int value);
void add_after(int value, int position);
void delete_element(int value);
void search_element(int value);
void display_dlist();
void count();
void reverse();
double_llist()
{
start = NULL;
Name shubhada subhash gunjal roll no-13

}
};
int main()
{
int choice, element, position;
double_llist dl;
while (1)
{
cout<<endl<<"----------------------------"<<endl;
cout<<endl<<"Operations on Doubly linked list"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"1.Create Node"<<endl;
cout<<"2.Add at begining"<<endl;
cout<<"3.Add after position"<<endl;
cout<<"4.Delete"<<endl;
cout<<"5.Display"<<endl;
cout<<"6.Count"<<endl;
cout<<"7.Reverse"<<endl;
cout<<"8.Quit"<<endl;
cout<<"Enter your choice : ";
cin>>choice;
switch ( choice )
{
case 1:
cout<<"Enter the element: ";
cin>>element;
dl.create_list(element);
cout<<endl;
break;
case 2:
cout<<"Enter the element: ";
cin>>element;
dl.add_begin(element);
cout<<endl;
break;
case 3:
cout<<"Enter the element: ";
cin>>element;
cout<<"Insert Element after postion: ";
cin>>position;
dl.add_after(element, position);
cout<<endl;
break;
case 4:
if (start == NULL)
{
cout<<"List empty,nothing to delete"<<endl;
break;
Name shubhada subhash gunjal roll no-13

}
cout<<"Enter the element for deletion: ";
cin>>element;
dl.delete_element(element);
cout<<endl;
break;
case 5:
dl.display_dlist();
cout<<endl;
break;
case 6:
dl.count();
break;
case 7:
if (start == NULL)
{
cout<<"List empty,nothing to reverse"<<endl;
break;
}
dl.reverse();
cout<<endl;
break;
case 8:
exit(1);
default:
cout<<"Wrong choice"<<endl;
}
}
return 0;
}
void double_llist::create_list(int value)
{
struct node *s, *temp;
temp = new(struct node);
temp->info = value;
temp->next = NULL;
if (start == NULL)
{
temp->prev = NULL;
start = temp;
}
else
{
s = start;
while (s->next != NULL)
s = s->next;
s->next = temp;
temp->prev = s;
Name shubhada subhash gunjal roll no-13

}
}
void double_llist::add_begin(int value)
{
if (start == NULL)
{
cout<<"First Create the list."<<endl;
return;
}
struct node *temp;
temp = new(struct node);
temp->prev = NULL;
temp->info = value;
temp->next = start;
start->prev = temp;
start = temp;
cout<<"Element Inserted"<<endl;
}
void double_llist::add_after(int value, int pos)
{
if (start == NULL)
{
cout<<"First Create the list."<<endl;
return;
}
struct node *tmp, *q;
int i;
q = start;
for (i = 0;i < pos - 1;i++)
{
q = q->next;
if (q == NULL)
{
cout<<"There are less than ";
cout<<pos<<" elements."<<endl;
return;
}
}
tmp = new(struct node);
tmp->info = value;
if (q->next == NULL)
{
q->next = tmp;
tmp->next = NULL;
tmp->prev = q;
}
else
{
Name shubhada subhash gunjal roll no-13

tmp->next = q->next;
tmp->next->prev = tmp;
q->next = tmp;
tmp->prev = q;
}
cout<<"Element Inserted"<<endl;
}
void double_llist::delete_element(int value)
{
struct node *tmp, *q;
if (start->info == value)
{
tmp = start;
start = start->next;
start->prev = NULL;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
}
q = start;
while (q->next->next != NULL)
{
if (q->next->info == value)
{
tmp = q->next;
q->next = tmp->next;
tmp->next->prev = q;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
}
q = q->next;
}
if (q->next->info == value)
{
tmp = q->next;
free(tmp);
q->next = NULL;
cout<<"Element Deleted"<<endl;
return;
}
cout<<"Element "<<value<<" not found"<<endl;
}
void double_llist::display_dlist()
{
struct node *q;
if (start == NULL)
{
Name shubhada subhash gunjal roll no-13

cout<<"List empty,nothing to display"<<endl;


return;
}
q = start;
cout<<"The Doubly Link List is :"<<endl;
while (q != NULL)
{
cout<<q->info<<" <-> ";
q = q->next;
}
cout<<"NULL"<<endl;
}
void double_llist::count()
{
struct node *q = start;
int cnt = 0;
while (q != NULL)
{
q = q->next;
cnt++;
}
cout<<"Number of elements are: "<<cnt<<endl;
}
void double_llist::reverse()
{
struct node *p1, *p2;
p1 = start;
p2 = p1->next;
p1->next = NULL;
p1->prev = p2;
while (p2 != NULL)
{
p2->prev = p2->next;
p2->next = p1;
p1 = p2;
p2 = p2->prev;
}
start = p1;
cout<<"List Reversed"<<endl;
}
Name shubhada subhash gunjal roll no-13
Name shubhada subhash gunjal roll no-13

4)write a program to implement Infix to prefix Convertion using static stack in c++
____________________________________________________________________________________
#include <iostream>
#include <string.h>
using namespace std;
const int MAX = 50 ;
class infix
{
private :
char target[MAX], stack[MAX] ;
char *s, *t ;
int top, l ;
public :
infix( ) ;
void setexpr ( char *str ) ;
void push ( char c ) ;
char pop( ) ;
void convert( ) ;
int priority ( char c ) ;
void show( ) ;
};
infix :: infix( )
{
top = -1 ;
strcpy ( target, "" ) ;
strcpy ( stack, "" ) ;
l=0;
}
void infix :: setexpr ( char *str )
{
s = str ;
strrev ( s ) ;
l = strlen ( s ) ;
* ( target + l ) = '\0' ;
t = target + ( l - 1 ) ;
}
void infix :: push ( char c )
{
if ( top == MAX - 1 )
cout<< "\nStack is full\n" ;
else
{
top++ ;
stack[top] = c ;
}
}
char infix :: pop( )
{
Name shubhada subhash gunjal roll no-13

if ( top == -1 )
{
cout<< "Stack is empty\n" ;
return -1 ;
}
else
{
char item = stack[top] ;
top-- ;
return item ;
}
}
void infix :: convert( )
{
char opr ;

while ( *s )
{
if ( *s == ' ' || *s == '\t' )
{
s++ ;
continue ;
}

if ( isdigit ( *s ) || isalpha ( *s ) )
{
while ( isdigit ( *s ) || isalpha ( *s ) )
{
*t = *s ;
s++ ;
t-- ;
}
}

if ( *s == ')' )
{
push ( *s ) ;
s++ ;
}

if ( *s == '*' || *s == '+' || *s == '/' ||


*s == '%' || *s == '-' || *s == '$' )
{
if ( top != -1 )
{
opr = pop( ) ;

while ( priority ( opr ) > priority ( *s ) )


Name shubhada subhash gunjal roll no-13

{
*t = opr ;
t-- ;
opr = pop( ) ;
}
push ( opr ) ;
push ( *s ) ;
}
else
push ( *s ) ;
s++ ;
}

if ( *s == '(' )
{
opr = pop( ) ;
while ( ( opr ) != ')' )
{
*t = opr ;
t-- ;
opr = pop ( ) ;
}
s++ ;
}
}

while ( top != -1 )
{
opr = pop( ) ;
*t = opr ;
t-- ;
}
t++ ;
}
int infix :: priority ( char c )
{
if ( c == '$' )
return 3 ;
if ( c == '*' || c == '/' || c == '%' )
return 2 ;
else
{
if ( c == '+' || c == '-' )
return 1 ;
else
return 0 ;
}
}
Name shubhada subhash gunjal roll no-13

void infix :: show( )


{
while ( *t )
{
cout << " " << *t ;
t++ ;
}
}

int main()
{
char expr[MAX] ;
infix q ;

cout << "\nEnter an expression in infix form: " ;


cin.getline ( expr, MAX ) ;

q.setexpr( expr ) ;
q.convert( ) ;

cout << "The Prefix expression is: " ;


q.show( ) ;
}

5)write a program to implement Postfix to Prefix Conversion using static stack in c++
____________________________________________________________________________________
#include<iostream>
#include<string.h>
using namespace std;
Name shubhada subhash gunjal roll no-13

#define MAX 10

class Stack{
char arr[MAX][MAX], st[MAX];
int top;
public: Stack():top(-1){}
void push(char[]);
char* pop();
int isFull();
int isEmpty();
void display();
};

int Stack::isFull(){
if(top==MAX)
return 1;
else
return 0;
}

int Stack::isEmpty()
{
if(top==-1)
return 1;
else
return 0;
}

void Stack::push(char str[]){


if(isFull())
cout<<"Stack is Full"<<endl;
else{
top++;
strcpy(arr[top],str);
cout<<str<<"is Pushed"<<endl;
}
}
char* Stack::pop() {
if(isEmpty())
cout<<"Stack is Empty"<<endl;
else{
strcpy(st,arr[top]);
top--;
}
cout<<st<<"is poped"<<endl;
return st;
}
Name shubhada subhash gunjal roll no-13

void Stack::display(){
if(isEmpty())
cout<<"Stack is Empty"<<endl;
else
for(int i=0;i<=top;i++)
cout<<arr[top];
}

int main(){
Stack ob;
char exp[MAX],t1[MAX],t2[MAX];
int i=0;

cout<<"Enter Postfix expression"<<endl;


cin>>exp;

while(exp[i]!='\0'){
if(( exp[i]>=65 && exp[i]<=90 )|| (exp[i]>=97 && exp[i]<=122)){
t1[0]=exp[i];
t1[1]='\0';
ob.push(t1);
}else{
strcpy(t1,ob.pop());
strcpy(t2,ob.pop());
strcat(t2,t1);
t1[0]=exp[i];
t1[1]='\0';
strcat(t1,t2);
ob.push(t1);
}
i++;
}
cout<<endl<<endl<<"Equivalent Prefix expression"<<endl;
ob.display();
return 0;
}
Name shubhada subhash gunjal roll no-13
Name shubhada subhash gunjal roll no-13

6)write a program to implement Postfix to Prefix Conversion using static stack in c++
____________________________________________________________________________________
#include<iostream>
#include<string.h>
using namespace std;
#define MAX 10
class Stack
{
char arr[MAX][MAX];
char str[10];
int top;
public:
Stack():top(-1){ }
void push(char[]);
char* pop();
int isFull();
int isEmpty();
void display();
};
int Stack::isFull()
{
if(top==MAX)
return 1;
else
return 0;
}
int Stack::isEmpty()
{
if(top==-1)
return 1;
else
return 0;
}
void Stack::push(char str[])
{
if(isFull())
{
cout<<"Stack is Full"<<endl;
}
else
{
top++;
strcpy(arr[top],str);
cout<<str<<"is Pushed"<<endl;
}
}
char* Stack::pop()
{
Name shubhada subhash gunjal roll no-13

if(isEmpty())
{
cout<<"Stack is Empty"<<endl;
}
else
{
strcpy(str,arr[top]);
top--;
}
cout<<str<<"is poped"<<endl;
return str;
}
void Stack::display(){
if(isEmpty())
{
cout<<"Stack is Empty"<<endl;
}
else
{
for(int i=0;i<=top;i++)
{
cout<<arr[top];
}
}
}
int main()
{
Stack ob;
char exp[20],t1[10],t2[10];
int i=0;
cout<<"Enter Postfix expression"<<endl;
cin>>exp;
while(exp[i]!='\0')
{
if(( exp[i]>=65&&exp[i]<=90 )|| (exp[i]>=97 && exp[i]<=122))
{
t1[0]=exp[i];
t1[1]='\0';
ob.push(t1);
}
else
{
strcpy(t1,ob.pop());
strcpy(t2,ob.pop());
strcat(t2,t1);
t1[0]=exp[i];
t1[1]='\0';
Name shubhada subhash gunjal roll no-13

strcat(t1,t2);
ob.push(t1);

}
i++;
}
cout<<"\n\nEquivallet Prefix expression"<<endl;
ob.display();
return 0;
}
Name shubhada subhash gunjal roll no-13

7)write a program to evaluate Infix expression in c++


_____________________________________________________________________________________
#include<iostream>
#include<cmath>
#include<stack>
using namespace std;
float scanNum(char ch) {
int value;
value = ch;
return float(value-'0');
}
int isOperator(char ch) {
if(ch == '+'|| ch == '-'|| ch == '*'|| ch == '/' || ch == '^')
return 1;
return -1;
}
int isOperand(char ch) {
if(ch >= '0' && ch <= '9')
return 1;
return -1;
}
float operation(int a, int b, char op)
{
if(op == '+')
return b+a;
else if(op == '-')
return b-a;
else if(op == '*')
return b*a;
else if(op == '/')
return b/a;
else if(op == '^')
return pow(b,a);
}
float postfixEval(string postfix) {
int a, b;
stack<float> stk;
string::iterator it;
for(it=postfix.begin(); it!=postfix.end(); it++) {
//read elements and perform postfix evaluation
if(isOperator(*it) != -1) {
a = stk.top();
stk.pop();
b = stk.top();
stk.pop();
stk.push(operation(a, b, *it));
}else if(isOperand(*it) > 0) {
stk.push(scanNum(*it));
Name shubhada subhash gunjal roll no-13

}
}
return stk.top();
}
main() {
string post = "53+62/*35*+";
cout << "The result is: "<<postfixEval(post);
}

8)write a program to evaluate postfix expretionin C++


____________________________________________________________________________________

#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
using namespace std;

const int MAX = 50 ;


Name shubhada subhash gunjal roll no-13

class postfix
{
private :

int stack[MAX] ;
int top, nn ;
char *s ;
public :
postfix( ) ;
void setexpr ( char *str ) ;
void push ( int item ) ;
int pop( ) ;
void calculate( ) ;
void show( ) ;
};
postfix :: postfix( )
{
top = -1 ;
}
void postfix :: setexpr ( char *str )
{
s = str ;
}
void postfix :: push ( int item )
{
if ( top == MAX - 1 )
cout<< endl << "Stack is full" ;
else
{
top++ ;
stack[top] = item ;
}
}
int postfix :: pop( )
{
if ( top == -1 )
{
cout<< endl << "Stack is empty" ;
//return ;
}
int data = stack[top] ;
top-- ;
return data ;
}
void postfix :: calculate( )
{
int n1, n2, n3 ;
while ( *s )
Name shubhada subhash gunjal roll no-13

{
if ( *s == ' ' || *s == '\t' )
{
s++ ;
continue ;
}
if ( isdigit ( *s ) )
{
nn = *s - '0' ;
push ( nn ) ;
}
else
{
n1 = pop( ) ;
n2 = pop( ) ;
switch ( *s )
{
case '+' :
n3 = n2 + n1 ;
break ;
case '-' :
n3 = n2 - n1 ;
break ;
case '/' :
n3 = n2 / n1 ;
break ;
case '*' :
n3 = n2 * n1 ;
break ;
case '%' :
n3 = n2 % n1 ;
break ;
case '$' :
n3 = pow ( n2 , n1 ) ;
break ;
default :
cout << "Unknown operator" ;
exit ( 1 ) ;
}

push ( n3 ) ;
}
s++ ;
}
}
void postfix :: show( )
{
nn = pop ( ) ;
Name shubhada subhash gunjal roll no-13

cout<< "Result is: " << nn ;


}

int main( )
{
char expr[MAX] ;
cout<< "\nEnter postfix expression to be evaluated : " ;
cin.getline ( expr, MAX ) ;
postfix q ;
q.setexpr ( expr ) ;
q.calculate( ) ;
q.show( ) ;
}

9) write a program to implement Linear Queue in C++


__________________________________________________________________________________
#include<iostream>
#include<conio.h>
using namespace std;
class node{
public: int data;
node *next;
};

class queue{
node *rear,*front,*temp;
public:queue(){
front=rear=NULL;
Name shubhada subhash gunjal roll no-13

}
void qinsert();
void qdelete();
void qdisplay();
~queue();
};

void queue::qinsert(){
temp=new node;
cout<<"Data :";
cin>>temp->data;
temp->next=NULL;
if(rear==NULL)
rear=front=temp;
else{
rear->next=temp;
rear=temp;
}
}
void queue::qdelete(){
if(front!=NULL) {
temp=front;
cout<<front->data<<"deleted \n";
front=front->next;
delete temp;
if(front==NULL)
rear=NULL;
}else
cout<<"Queue Empty..";
}
void queue::qdisplay(){
temp=front;
while(temp!=NULL){
cout<<temp->data<<endl;
temp=temp->next;
}
}
queue::~queue(){
while(front!=NULL){
temp=front;
front=front->next;
delete temp;
}
}
int main(){
queue obj; char ch;
do {
cout<< " i. insert\n d. Delete\n s. Display\n q. quit ";
Name shubhada subhash gunjal roll no-13

cin>>ch;
switch(ch){
case 'i':obj.qinsert();
break;
case 'd':obj.qdelete();
break;
case 's':obj.qdisplay();
}
}while(ch!='q');
}
Output:

10)write a program to implement Linear Circular Queue in c++


____________________________________________________________________________________
#include <iostream>
#define MAX 5
using namespace std;
class Circular_Queue
{
private:
int *cqueue_arr;
int front, rear;
public:
Circular_Queue()
{
cqueue_arr = new int [MAX];
rear = front = -1;
}
void insert(int item)
{
if ((front == 0 && rear == MAX-1) || (front == rear+1))
{
Name shubhada subhash gunjal roll no-13

cout<<"Queue Overflow \n";


return;
}
if (front == -1)
{
front = 0;
rear = 0;
}
else
{
if (rear == MAX - 1)
rear = 0;
else
rear = rear + 1;
}
cqueue_arr[rear] = item ;
}
void del()
{
if (front == -1)
{
cout<<"Queue Underflow\n";
return ;
}
cout<<"Element deleted from queue is : "<<cqueue_arr[front]<<endl;
if (front == rear)
{
front = -1;
rear = -1;
}
else
{
if (front == MAX - 1)
front = 0;
else
front = front + 1;
}
}
void display()
{
int front_pos = front, rear_pos = rear;
if (front == -1)
{
cout<<"Queue is empty\n";
return;
}
cout<<"Queue elements :\n";
if (front_pos <= rear_pos)
Name shubhada subhash gunjal roll no-13

{
while (front_pos <= rear_pos)
{
cout<<cqueue_arr[front_pos]<<" ";
front_pos++;
}
}
else
{
while (front_pos <= MAX - 1)
{
cout<<cqueue_arr[front_pos]<<" ";
front_pos++;
}
front_pos = 0;
while (front_pos <= rear_pos)
{
cout<<cqueue_arr[front_pos]<<" ";
front_pos++;
}
}
cout<<endl;
}
};
int main()
{
int choice, item;
Circular_Queue cq;
do
{
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Input the element for insertion in queue : ";
cin>>item;
cq.insert(item);
break;
case 2:
cq.del();
break;
case 3:
cq.display();
Name shubhada subhash gunjal roll no-13

break;
case 4:
break;
default:
cout<<"Wrong choice\n";
}
}
while(choice != 4);
return 0;
}

11)Write a Program to Implement Priority Queue


_____________________________________________________________________________________
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
class node
{
public:
int priority;
Name shubhada subhash gunjal roll no-13

int info;
node *link;
};
class Priority_Queue
{
node *front;
public:
Priority_Queue()
{
front = NULL;
}
void insert(int item, int priority)
{
node *tmp, *q;
tmp = new node;
tmp->info = item;
tmp->priority = priority;
if (front == NULL || priority < front->priority)
{
tmp->link = front;
front = tmp;
}
else
{
q = front;
while (q->link != NULL && q->link->priority <= priority)
q=q->link;
tmp->link = q->link;
q->link = tmp;
}
}
void del()
{
node *tmp;
if(front == NULL)
cout<<"Queue Underflow\n";
else
{
tmp = front;
cout<<"Deleted item is: "<<tmp->info<<endl;
front = front->link;
free(tmp);
}
}
void display()
{
node *ptr;
ptr = front;
Name shubhada subhash gunjal roll no-13

if (front == NULL)
cout<<"Queue is empty\n";
else
{ cout<<"Queue is :\n";
cout<<"Priority Item\n";
while(ptr != NULL)
{
cout<<ptr->priority<<" "<<ptr->info<<endl;
ptr = ptr->link;
}
}
}
};
int main()
{
int choice, item, priority;
Priority_Queue pq;
do
{
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Input the item value to be added in the queue : ";
cin>>item;
cout<<"Enter its priority : ";
cin>>priority;
pq.insert(item, priority);
break;
case 2:
pq.del();
break;
case 3:
pq.display();
break;
case 4:
break;
default :
cout<<"Wrong choice\n";
}
}
while(choice != 4);
return 0;
Name shubhada subhash gunjal roll no-13

12)write a program to implement Double Ended Queue in C++


_____________________________________________________________________________________
#include<iostream.>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class dqll
{
char data;
dqll *next;
dqll *prev;
Name shubhada subhash gunjal roll no-13

public:
void insert();
void del();
void display();
};dqll *node;
void dqll::insert()
{
dqll *temp;
temp=new dqll;
char a;
cout<<endl<<"enter the element : ";
cin>>a;
if(node==NULL)
{
temp->data=a;
temp->next=temp;
temp->prev=temp;
node=temp;
}
else
{
int c;
cout<<"insert at d beg/end (1/2) : ";
cin>>c;
switch(c)
{
case 1:
{
dqll *r;
r=node;
temp->data=a;
temp->next=node;
node->prev=temp;
while(r->next!=node)
{
r=r->next;
}
r->next=temp;
temp->prev=r;
node=temp;
break;
}
case 2:
{
dqll *r;
r=node;
while(r->next!=node)
{
Name shubhada subhash gunjal roll no-13

r=r->next;
}
temp->data=a;
r->next=temp;
temp->prev=r;
temp->next=node;
node->prev=temp;
break;
}
}
} }
void dqll::del()
{
dqll *temp;
temp=node;
int op;
if(node->next==node)
{
node=NULL;
cout<<endl<<"---queue with single item deleted---"<<endl;
}
Else
{
cout<<"deletion at d beg/end ??? (1/2) : ";
cin>>op;
switch(op)
{
case 1:
{
while(temp->next!=node)
{
temp=temp->next;
}
node=node->next;
node->prev=temp;
temp->next=node;
break; }
case 2:
{
dqll *r;
while(temp->next!=node)
{
r=temp;
temp=temp->next;
}
r->next=node;
node->prev=r;
break;
Name shubhada subhash gunjal roll no-13

}
}
}
}
void dqll::display()
{
dqll *temp;
temp=node;
if(node==NULL)
{
cout<<endl<<"---queue is empty---";
}
else
{
cout<<endl<<"---contents---"<<endl;
while(temp->next!=node)
{
cout<<temp->data<<endl;
temp=temp->next;
}
cout<<temp->data;
}
}
int main()
{
dqll l;
int op;
char ch;
do
{
cout<<endl<<"---enter ur choice---"<<endl<<"press!!!"<<endl;
cout<<"1->insert"<<endl<<"2->delete"<<endl<<"3->display"<<endl;
cout<<"ur option : ";
cin>>op;
switch(op)
{
case 1:
{
l.insert();
break;
}
case 2:
{
l.del();
break;
}
case 3:
{
Name shubhada subhash gunjal roll no-13

l.display();
break;
}
default:
{
cout<<endl<<"---invalid option!!!---"<<endl;
}
}
cout<<endl<<"do u wanna continue???"<<endl<<"(y/n) : ";
cin>>ch;
}
while(ch=='y');
getch();
}
Output:

Vous aimerez peut-être aussi