Articles by "Ds"
Showing posts with label Ds. Show all posts
Print Friendly and PDF
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include <iostream>
using namespace std;
struct Node
{
char name;
int number;
char contactNo;
char email;
int count;
struct Node* next;
};
class ContatBook
{
Node* first;
Node* current;
Node* newNode;
public:
ContatBook()
{
first=0;
current=0;
newNode=0;
}
void clearInput(void);
void addNewcontact(void)
{
newNode = (struct Node*)malloc(sizeof(struct Node));
if(first==NULL)
first = current = newNode;
else
{
current = first;
while(current->next != NULL)current = current->next;
current->next = newNode;
current = newNode;
}
cout<<"Enter contact name"<<endl;
current->name;
cout<<"Enter contact Phone number"<<endl;
current->contactNo;
cout<<"Enter contact email"<<endl;
current->email;
cout<<"contact added!"<<endl;
current->count++;
current->next = NULL;
}
void listAll(void)
{
if(first==NULL)
puts("There are no contacts to display!");
else
{
cout<<"Acct No. is:"<<endl;
cout<<"Name is:"<<endl;
cout<<"Contact No. is:"<<endl;
cout<<"Email is:"<<endl;
current=first;
do {
cout<<"\n"<<endl;
current->number;
current->name;
current->contactNo;
current->email;
}
while((current=current->next) != NULL);
}
}
void deletecontact(void)
{
int record;
struct Node *previous;
if(first==NULL)
{
cout<<"There are no contacts to delete!"<<endl;
return;
}
listAll();
cout<<"Enter contact account number to delete: "<<endl;
cin>>record;
current = first;
while(current != NULL)
{
if(current->number == record)
{ if(current == first)
first=current->next;
else
previous->next = current->next;
free(current);  cout<<"contact %d deleted!\n"<<record<<endl;
return;
}
else
{
previous = current;
current = current->next;
}
}
cout<<"contact %d not found!\n"<<record<<endl;
}
void modifycontact(void)
{
int record, result;
if(first==NULL)
{
cout<<"There are no contacts to modify!"<<endl;
return;
}
listAll();
cout<<"Enter contact account number to modify or change: "<<endl; cin>>record;
result = findnum(record);
if( result >0 )
{
cout<<"Contact:"<<current->number<<endl;
cout<<"Name:"<<current->name<<endl;
if(prompt())
current->name;
cout<<"Contact No:"<<current->contactNo<<endl;
if(prompt())
current->contactNo;
cout<<"Email:"<<current->email<<endl;
if(prompt())
current->email;
return;
}
cout<<"contact %d was not found!\n"<<record<<endl;
}
int findcontact(void)
{
char buff[20];
if(first==NULL)
{
cout<<"There are no contacts to find!"<<endl;
return 1;
}
cout<<"Enter contact name: "<<endl;
fflush(stdin); current = first;
while(current != NULL)
{
if((current->name, buff) == 0 )
{
cout<<"Acct#"<<endl;
cout<<"Name"<<endl;
cout<<"Phone"<<endl;
cout<<"Email"<<endl;
cout<<"\n"<<endl;
current->number;
current->name;
current->contactNo;
current->email;
return 0;
}
else
{
current = current->next;
}
}
cout<<"contact %s was not found!\n"<<buff;
return 1;
}
int prompt(void)
{
char ch;
fflush(stdin);
cout<<"Update? (Y to update any other key to not)"<<endl;
ch = getchar();
ch = toupper(ch);
fflush(stdin);
if(ch == 'Y')
{
cout<<"Enter new value: "<<endl;
return(1);
}
else
return(0);
}
int findnum (int recordnum)
{
int record;
record = recordnum;
current = first;
while(current != NULL)
{
if(current->number == record)
{
return 1;
}
else
{ current = current->next;
}
}
return -1;
}
void display()
{
Node *temp=first;
while(temp != NULL)
{
cout<<temp->contactNo<<endl;
temp=temp->next;
}
}
};
void main()
{
//Node N;
ContatBook C;
int choice;
do
{
cout<<"\nWelcome To The Contact Book"<<endl;
cout<<"-- -----------------------------"<<endl;
cout<<"1 - Add a new contact"<<endl;
cout<<"2 - Delete contact"<<endl;
cout<<"3 - List all contacts"<<endl;
cout<<"4 - Modify contact"<<endl;
cout<<"5 - Find a contact by name"<<endl;
cout<<"-- -----------------------------"<<endl;
cout<<"Q - Save and quit\n"<<endl;
cout<<"\tYour choice:"<<endl;
cin>>choice;
choice = getchar();
choice = toupper(choice);
switch(choice)
{
case '1':
{
cout<<"Add a new contact\n"<<endl;
C.addNewcontact();
break;
}
case '2':
{
cout<<"Delete a contact\n"<<endl;
C.deletecontact();
break;
}
case '3':
{
cout<<"List all contacts\n"<<endl;
C.listAll();
break;
}
case '4':
{
cout<<"Modify a contact\n"<<endl;
C.modifycontact();
break;
}
case '5':
{
cout<<"Find a contact by name\n"<<endl;
C.findcontact();
break;
}
case 'Q':
{
cout<<"Save and quit\n"<<endl;
default:
break;
}
}
}while(choice != 'Q');
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include < iostream.h >
const int MAX = 10 ; class array 
{ 
private : 
int arr[MAX] ; 
int count ; 
public : 
array( ) ; 
void add ( int item ) ; 
void sort( ) ; 
void display( ) ; 
} ; 
array :: array( ) 
{ 
count = 0 ; 
for ( int i = 0 ; i < MAX ; i++ ) 
arr[i] = 0 ; 
} 
void array :: add ( int item ) 
{ 
if ( count < MAX ) 
{ 
arr[count] = item ; 
count++ ; } 
else 
cout << "\nArray is full" << endl ; 
} 
void array :: sort( ) { 
int temp ; 

for ( int i = 1 ; i <= count - 1 ; i++ ) 
{ 
for ( int j = 0 ; j < i ; j++ ) 
{ 
if ( arr[j] > arr[i] ) 
{ 
temp = arr[j] ; arr[j] = arr[i] ; 
for ( int k = i ; k > j ; k-- ) 
arr[k] = arr[k - 1] ; 
arr[k + 1] = temp ; 
} 
} 
} 
} 
void array :: display( ) { 
for ( int i = 0 ; i < count ; i++ ) 
cout << arr[i] << "\t" ; 
cout << endl ; 
} void main( ) 
{ 
array a ; a.add ( 25 ) ; 
a.add ( 17 ) ; 
a.add ( 31 ) ; 
a.add ( 13 ) ; 
a.add ( 2 ) ; cout << "\nInsertion sort.\n" ; 
cout << "\nArray before sorting:" << endl ; 
a.display( ) ; 
a.sort( ) ; cout << "\nArray after insertion sorting:" << endl ; 
a.display( ) ; 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include< iostream.h >
#include< conio.h > class cirdlink 
{ 
struct node 
{ 
int data; 
node *rnext; 
node *lnext; 
}
*new1,*head,*tail,*ptr,*temp; 
public: 
cirdlink() 
{ 
head=tail=NULL; 
} 
void creation(); void insertion(); 
void deletion(); 
void display(); 
}; void cirdlink :: creation() 
{ 
if(head==NULL) { 
new1=new node[sizeof(node)]; 
new1->rnext=NULL; 
new1->lnext=NULL; 
cout<<"enter student number :"; 
cin>>new1->data; 
head=new1; 
tail=new1; 
head->rnext=tail; 
head->lnext=tail; 
tail->rnext=head; 
tail->lnext=head; 
} 
else 
cout<<" creation done only once !"; 
} 
void cirdlink :: insertion() 
{ 
int i,pos; 
new1=new node[sizeof(node)]; 
new1->rnext=NULL; 
new1->lnext=NULL; 
cout<<"enter student number :"; 
cin>>new1->data; 
cout<<"enter position you want to insert :"; 
cin>>pos; 
if(pos==1) 
{ 
new1->rnext=head; 
head=new1; 
tail->lnext=head; 
tail->rnext=head; 
head->lnext=tail; 
} 
else 
{ 
i=1; 
temp=head; 
while(i < pos-1 && temp->rnext!=tail) 
{ 
i++; 
temp=temp->rnext; 
} if(temp->rnext==tail) 
{ 
new1->rnext=tail->rnext; 
tail->rnext=new1; 
new1->lnext=tail; 
tail=new1; 
head->lnext=tail; 
} 
else 
{ 
new1->rnext=temp->rnext; 
new1->lnext=temp; 
temp->rnext=new1; 
new1->rnext->lnext=new1; 
} 
} 
} 
void cirdlink :: deletion() 
{ 
int pos,i; 
cout<<"Enter Position you want to Delete ?"; 
cin>>pos; 
if(pos==1 && head!=tail) 
{ 
ptr=head; 
head=head->rnext; 
head->lnext=tail; tail->rnext=head; 
delete ptr; 
} 
else 
{ 
i=1; 
temp=head; 
while(i < pos-1 && temp->rnext!=tail) 
{ 
i++; 
temp=temp->rnext; 
} 
if(temp->rnext!=tail) 
{ ptr=temp->rnext; 
temp->rnext=ptr->rnext; 
ptr->rnext->lnext=ptr->lnext; 
delete ptr; 
} 
else 
{ 
if(temp->rnext==tail && head!=tail) 
{ 
ptr=tail; 
tail=temp; 
tail->rnext=head; 
head->lnext=tail; 
delete ptr; 
} else 
{ 
head=NULL; 
tail=NULL; 
delete head; 
delete tail; } 
} } 
} void cirdlink::display() 
{ 
int ch; 
cout<<"1.forward 
2.backward:"; 
cout<<"Enter your choice<1/2>?"; 
cin>>ch; switch(ch) 
{ 
case 1: if(head!=NULL) 
{ 
temp=head; 
while(temp!=tail) 
{ 
cout<< temp->data<<" "; 
temp=temp->rnext; 
} 
if(temp==tail) 
cout<< temp->data; 
} 
break; case 2 : if(tail!=NULL) 
{ 
temp=tail; 
while(temp!=head) 
{ cout<< temp->data<<" "; 
temp=temp->lnext; } 
if(temp==head) cout<< temp->data; 
} break; 
} 
} 
void main() 
{ 
cirdlink c1; 
int ch; 

char op; 
do 
{ 
clrscr(); 
cout<<"----------Menu------------"; 
cout<<" 1.Creation 
2.Insertion 
3.Deletion 
4.Display "; 
cout<<"Enter Your choice <1..4> ?"; 
cin>>ch; switch(ch) 
{ 
case 1 : c1.creation(); 
break; 
case 2 : c1.insertion(); 
break; 
case 3 : c1.deletion(); 
break; 
case 4 : c1.display(); 
break; 
} 
cout<<"Do you want to continue < Y/N > ?"; 
cin>>op; 
}
while(op=='y' || op=='Y'); 
getch(); 

}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include< iostream.h> 
#include< conio.h> 
#define SIZE 20 
class stack 
{ 
int a[SIZE]; 
int tos; // Top of Stack 
public: 
stack(); 
void push(int); 
int pop(); 
int isempty(); 
int isfull(); 
}; 
stack::stack() 
{ 
tos=0; //Initialize Top of Stack 
} 
int stack::isempty() 
{ 
return (tos==0?1:0); 
} 
int stack::isfull() 
{ 
return (tos==SIZE?1:0); 
} 
void stack::push(int i) 
{ 
if(!isfull()) 
{ 
cout<<"Pushing "<< i<< endl; 
a[tos]=i; 
tos++; 
} 
else 
{ 
c0ut<<"Stack overflow error ! 
Possible Data Loss !"; 
} 
} 
int stack::pop() 
{ 
if(!isempty()) 
{ 
cout<<"Popping "<< a[tos-1]<< endl; 
return(a[--tos]); 
} 
else 
{ 
cout<<"Stack is empty! What to pop...!"; 
} 
return 0; 
} 
void reverse(stack s) 
{ 
stack s2; 
while(!s.isempty()) 
{ 
s2.push(s.pop()); 
} 
cout<<"Reversed contents of the stack..."<< endl; 
while(!s2.isempty()) 
{ 
cout<< s2.pop()<< endl; 
} 
}//end of fn. 
void main() 
{ 
clrscr(); 
stack s; 
s.push(1); 
s.push(2); 
s.push(3); 
reverse(s); 
getch(); 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
# include < iostream.h >
# include < conio.h > 
# define SIZE 20 
class queue 
{ 
int a[SIZE]; 
int front; 
int rear; 
public: 
queue(); 
~queue(); 
void insert(int i); 
int remove(); 
int isempty(); 
int isfull(); 
}; 
queue::queue() 
{ 
front=0; 
rear=0; 
} 
queue::~queue() 
{ 
delete []a; 
} 
void queue::insert(int i) 
{ 
if(isfull()) 
{ 
cout<<"*Queue is FULL !!!No insertion allowed further.*"; 
return; 
} 
a[rear] = i; 
rear++; 
} 
int queue::remove() 
{ 
if(isempty()) 
{ 
cout<<"*Queue Empty !!!Value returned will be garbage.*"; 
return (-9999); 
} 
return(a[front++]); 
} 
int queue::isempty() 
{ 
if(front == rear) 
return 1; 
else 
return 0; 
} 
int queue::isfull() 
{ 
if(rear == SIZE) 
return 1; 
else 
return 0; 
} 
void main() 
{ 
clrscr(); 
queue q; 
q.insert(1); 
q.insert(2); 
cout<<""<< q.remove(); 
cout<<""<< q.remove(); 
cout<<"" << q.remove(); 
getch(); 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include < iostream.h > 
 const int MAX = 10 ; 
class array 
{ 
private : 
int arr[MAX] ; 
int count ; 
public : 
array( ) ; 
void add ( int num ) ; 
void makeheap(int ) ; 
void heapsort( ) ; 
void display( ) ; 
} ; 
array :: array( ) 
{ 
count = 0 ; 
for ( int i = 0 ; i < MAX ; i++ ) 
arr[MAX] = 0 ; 
} 
void array :: add ( int num ) 
{ 
if ( count < MAX ) 
{ 
arr[count] = num ; 
count++ ; 
} 
else 
cout << "\nArray is full" << endl ; 
} 
void array :: makeheap(int c) 
{ 
for ( int i = 1 ; i < c ; i++ ) 
{ 
int val = arr[i] ; 
int s = i ; 
int f = ( s - 1 ) / 2 ; 
while ( s > 0 && arr[f] < val ) 
{ 
arr[s] = arr[f] ; 
s = f ; 
f = ( s - 1 ) / 2 ; 
} 
arr[s] = val ; 
} 
} 
void array :: heapsort( ) 
{ 
for ( int i = count - 1 ; i > 0 ; i-- ) 
{ 
int ivalue = arr[i] ; 
arr[i] = arr[0] ; 
arr[0]=ivalue; 
makeheap(i); 
} 
} 
void array :: display( ) 
{ 
for ( int i = 0 ; i < count ; i++ ) 
cout << arr[i] << "\t" ; 
cout << endl ; 
} 
void main( ) 
{ 
array a ; 
a.add ( 11 ) ; 
a.add ( 2 ) ; 
a.add ( 9 ) ; 
a.add ( 13 ) ; 
a.add ( 57 ) ; 
a.add ( 25 ) ; 
a.add ( 17 ) ; 
a.add ( 1 ) ; 
a.add ( 90 ) ; 
a.add ( 3 ) ; 
a.makeheap(10) ; 
cout << "\nHeap Sort.\n" ; 
cout << "\nBefore Sorting:\n" ; 
a.display( ) ; 
a.heapsort( ) ; 
cout << "\nAfter Sorting:\n" ; 
a.display( ) ; 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
# include < iostream.h >
# include < conio.h > 
# define SIZE 20 
class queue 
{ 
int a[SIZE]; 
int front; 
int rear; 
public: 
queue(); 
~queue(); 
void insert(int i); 
int remove(); 
int isempty(); 
int isfull(); 
}; 
queue::queue() 
{ 
front=0; 
rear=0; 
} 
queue::~queue() 
{ 
delete []a; 
} 
void queue::insert(int i) 
{ 
if(isfull()) 
{ 
cout<<"*Queue is FULL !!!No insertion allowed further.*"; 
return; 
} 
a[rear] = i; 
rear++; 
} 
int queue::remove() 
{ 
if(isempty()) 
{ 
cout<<"*Queue Empty !!!Value returned will be garbage.*"; 
return (-9999); 
} 
return(a[front++]); 
} 
int queue::isempty() 
{ 
if(front == rear) 
return 1; 
else 
return 0; 
} 
int queue::isfull() 
{ 
if(rear == SIZE) 
return 1; 
else 
return 0; 
} 
void main() 
{ 
clrscr(); 
queue q; 
q.insert(1); #include< iostream > 
#include< cstdlib > 
using namespace std; 
class hash 
{ 
private: 
int hash_pos; 
int array[40]; 
public: 
hash(); 
void insert(); 
void search(); 
int Hash(int ); 
int reHash(int ); 
void Delete(); 
};
hash::hash() 
{ 
for(int i = 0; i < 40; i++) 
{ 
array[i] = '*'; 
} 
} 
void hash::insert() 
{ 
int data; 
int count = 0; 
cout<<"Enter the data to insert: "; 
cin>>data; 
hash_pos = Hash(data); 
if(hash_pos >= 40) 
{ 
hash_pos = 0; 
} 
while(array[hash_pos] != '*') 
{ 
hash_pos = reHash(hash_pos); 
count++; 
if(count>=40) 
{ 
cout<<"Memory Full!!No space is avaible for storage"; 
break; 
} 
} 
if(array[hash_pos] == '*') 
{ 
array[hash_pos] = data; 
} 
cout<<"Data is stored at index "<< hash_pos<< endl; 
} 
int hash::Hash(int key) 
{ 
return key%100; 
} 
int hash::reHash(int key) 
{ 
return (key+1)%100; 
} 
void hash::search() 
{ 
int key,i; 
bool isFound = false; 
cout<<"Enter the key to search: "; 
cin>>key; 
for(i = 0; i < 40; i++) 
{ 
if(array[i] == key) 
{ 
isFound = true; 
break; 
} 
} 
if(isFound) 
{ 
cout<<"The key is found at index "<< i << endl; 
} 
else 
{ 
cout<<"No record found!!"<< endl; 
} 
} 
void hash::Delete() 
{ 
int key,i; 
bool isFound = false; 
cout<<"Enter the key to delete: "; 
cin>>key; 
for(i = 0; i < 40; i++) 
{ 
if(array[i] == key) 
{ 
isFound = true; 
break; 
} 
} 
if(isFound) 
{ 
array[i] = '*'; 
cout<<"The key is deleted"<< endl; 
} 
else 
{ 
cout<<"No key is Found!!"; 
} 
} 
int main() 
{ 
hash h; 
int choice; 
while(1) 
{ 
cout<<"\n1. Insert\n2. Search\n3. Delete\n4. Exit\n"; 
cout<<"Enter your choice: "; 
cin>>choice; 
switch(choice) 
{ 
case 1: 
h.insert(); 
break; 
case 2: 
h.search(); 
break; 
case 3: 
h.Delete(); 
break; 
case 4: 
exit(0); 
default: 
cout<<"\nEnter correct option\n"; 
break; 
} 
} 
return 0; 
}
q.insert(2); 
cout<<""<< q.remove(); 
cout<<""<< q.remove(); 
cout<<"" << q.remove(); 
getch(); 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include<iostream.h> 
#include<conio.h> 
#include<stdio.h> 
#include<stdlib.h> 
class path 
{ 
int n; 
int p[10][10]; 
int a[10][10]; 
int c[10][10]; 
public: 
void get(); 
void pm(); 
void ap(); 
void disp(); 
}; 
void path::get() 
{ 
int i,j,k; 
clrscr(); 
cout<<"Enter the no. of nodes in the graph :"; 
cin>>n; 
cout<<"Enter the adjacency matrix :"; 
for(i=1;i<=n;i++) 
{ 
for(j=1;j<=n;j++) 
{ 
cin>>a[i][j]; 
p[i][j]=0; 
}
} 
cout<<"Enter The cost matrix is :"; 
for(i=1;i<=n;i++) 
{ 
for(j=1;j<=n;j++) 
{ 
cin>>c[i][j]; 
} 
} 
for(i=1;i<=n;i++) 
{ 
for(j=1;j<=n;j++) 
{ 
p[i][j]=a[i][j]; 
} 
} 
} 
void path::disp() 
{ 
// cout<<"The output matrix for the given graph is :"; 
for(int i=1;i<=n;i++) 
{ 
for(int j=1;j<=n;j++) 
{ 
cout<<p[i][j]<< " "; 
} 
cout<<endl; 
} 
} 
void path::pm() 
{ 
int i,j,k; 
for(k=1;k<=n;k++) 
{ 
for(i=1;i<=n;i++) 
{ 
for(j=1;j<=n;j++) 
{ 
p[i][j]=p[i][j] || p[i][k] && p[k][j]; 
} 
} 
} 
} 
void path::ap() 
{ 
int i,j,k; 
for(i=1;i<=n;i++) 

{ 

for(j=1;j<=n;j++) 
{ 
p[i][j]=c[i][j]; 
} 
} 
for(k=1;k<=n;k++) 
{ 
for(i=1;i<=n;i++) 
{ 
for(j=1;j<=n;j++) 
{ 
if(p[i][j]<p[i][k]+p[k][j]) 
{ 
p[i][j]=p[i][j]; 
} 
else 
{ 
p[i][j]=p[i][k]+p[k][j]; 
}
} 
} 
} 
} 
void main() 
{ 
path p; 
p.get(); 
p.pm(); 
cout<<"path matrix is :"; 
p.disp(); 
getch(); 
p.ap(); 
cout<<"all pair shortest path matrix is :"; 
p.disp(); 
getch(); 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include < iostream > 
#include < cstdlib > 
#include < string > 
using namespace std; 
class Dllist 
{ 
private: 
typedef struct Node 
{ 
string name; 
Node* next; 
Node* prev; 
}; 
Node* head; 
Node* last; 
public: 
Dllist() 
{ 
head = NULL; 
last = NULL; 
} 
bool empty() const { return head==NULL; } 
friend ostream& operator<<(ostream& ,const Dllist& ); 
void Insert(const string& ); 
void Remove(const string& ); 
}; 
void Dllist::Insert(const string& s) 
{ 
// Insertion into an Empty List. 
if(empty()) 
{ 
Node* temp = new Node; 
head = temp; 
last = temp; 
temp->prev = NULL; 
temp->next = NULL; 
temp->name = s; 
} 
else 
{ 
Node* curr; 
curr = head; 
while( s>curr->name && curr->next != last->next) 
curr = curr->next; 
if(curr == head) 
{ 
Node* temp = new Node; 
temp->name = s; 
temp->prev = curr; 
temp->next = NULL; 
head->next = temp; 
last = temp; 
// cout<<" Inserted "<< s <<" After " << curr->name << endl; 
} 
else 
{ 
if(curr == last && s>last->name) 
{
last->next = new Node; 
(last->next)->prev = last; 
last = last->next; 
last->next = NULL; 
last->name = s; 
// cout<<" Added "<< s <<" at the end "<< endl; 
} 
else 
{ 
Node* temp = new Node; 
temp->name = s; 
temp->next = curr; 
(curr->prev)->next = temp; 
temp->prev = curr->prev; 
curr->prev = temp; 
// cout<<" Inserted "<< s <<" Before "<< curr->name << endl; 
} 
} 
} 
} 
ostream& operator<<(ostream& ostr, const Dllist& dl ) 
{ 
if(dl.empty()) ostr<<" The list is empty. "<< endl; 
else 
{ 
Dllist::Node* curr; 
for(curr = dl.head; curr != dl.last->next; curr=curr->next) 
ostr<< curr->name<<" "; 
ostr<< endl; 
ostr<< endl; 
return ostr; 
} 
} 
void Dllist::Remove(const string& s) 
{ 
bool found = false; 
if(empty()) 
{ 
cout<<" This is an empty list! "<< endl; 
return; 
} 
else 
{ 
Node* curr; 
for(curr = head; curr != last->next; curr = curr->next) 
{ 
if(curr->name == s) 
{ 
found = true; 
break; 
} 
} 
if(found == false) 
{ 
cout<<" The list does not contain specified Node"<< endl; 
return; 
} 
else 
{ 
// Curr points to the node to be removed. 
if (curr == head && found) 
{ 
if(curr->next != NULL) 
{ 
head = curr->next; 
delete curr; 
return; 
} 
else 
{ 
delete curr; 
head = NULL; 
last = NULL; 
return; 
} 
} 
if (curr == last && found) 
{ 
last = curr->prev; 
delete curr; 
return; 
} 
(curr->prev)->next = curr->next; 
(curr->next)->prev = curr->prev; 
delete curr; 
} 
} 
} 
int main() 
{ 
Dllist d1; 
int ch; 
string temp; 
while(1) 
{ 
cout<< endl; 
cout<<" Doubly Linked List Operations "<< endl; 
cout<<" ------------------------------"<< endl; 
cout<<" 1. Insertion "<< endl; 
cout<<" 2. Deletion "<< endl; 
cout<<" 3. Display "<< endl; 
cout<<" 4. Exit "<< endl; 
cout<<" Enter your choice : "; 
cin>>ch; 
switch(ch) 
{ 
case 1: cout<<" Enter Name to be inserted : "; 
cin>>temp; 
d1.Insert(temp); 
break; 
case 2: 
cout<<" Enter Name to be deleted : "; 
cin>>temp; 
d1.Remove(temp); 
break; 
case 3: 
cout<<" The List contains : "; 
cout<< d1; 
break; 
case 4: system("pause"); 
return 0; 
break; 
} 
} 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
#include<conio.h > 
#include< iostream.h > 
#include< stdlib.h > 
void create(); // For creating a graph 
void dfs(); // For Deapth First Search(DFS) Traversal. 
void bfs(); // For Breadth First Search(BFS) Traversal. 
struct node // Structure for elements in the graph 
{ 
int data,status; 
struct node *next; 
struct link *adj; 
}; 
struct link // Structure for adjacency list 
{ 
struct node *next; 
struct link *adj; 
}; 
struct node *start,*p,*q; 
struct link *l,*k; 
int main() 
{ 
int choice; 
clrscr(); 
create(); 
while(1) 
{ 
cout<<" 
1: DFS 
2: BSF 
3: Exit 
Enter your choice: "; 
cin>>choice; 
switch(choice) 
{ 
case 1: 
dfs(); 
break; 
case 2: 
bfs(); 
break; 
case 3: 
exit(0); 
break; 
default: 
cout<<" 
Incorrect choice! 
Re-enter your choice."; 
getch(); 
} 
} 
return 0; 
} 
void create() // Creating a graph 
{ 
int dat,flag=0; 
start=NULL; 
cout<<" 
Enter the nodes in the graph(0 to end): "; 
while(1) 
{ 
cin>>dat; 
if(dat==0) 
break; 
p=new node; 
p->data=dat; 
p->status=0; 
p->next=NULL; 
p->adj=NULL; 
if(flag==0) 
{ 
start=p; 
q=p; 
flag++; 
} 
else 
{ 
q->next=p; 
q=p; 
} 
} 
p=start; 
while(p!=NULL) 
{ 
cout<<"Enter the links to "<< p->data<<" (0 to end) : "; 
flag=0; 
while(1) 
{ 
cin>>dat; 
if(dat==0) 
break; 
k=new link; 
k->adj=NULL; 
if(flag==0) 
{ 
p->adj=k; 
l=k; 
flag++; 
} 
else 
{ 
l->adj=k; 
l=k; 
} 
q=start; 
while(q!=NULL) 
{ 
if(q->data==dat) 
k->next=q; 
q=q->next; 
} 
} 
p=p->next; 
} 
cout<<"-------------------------"; 
return; 
} 
// Deapth First Search(DFS) Traversal. 
void bfs() 
{ 
int qu[20],i=1,j=0; 
p=start; 
while(p!=NULL) 
{ 
p->status=0; 
p=p->next; 
} 
p=start; 
qu[0]=p->data; 
p->status=1; 
while(1) 
{ 
if(qu[j]==0) 
break; 
p=start; 
while(p!=NULL) 
{ 
if(p->data==qu[j]) 
break; 
p=p->next; 
} 
k=p->adj; 
while(k!=NULL) 
{ 
q=k->next; 
if(q->status==0) 
{ 
qu[i]=q->data; 
q->status=1; 
qu[i+1]=0; 
i++; 
} 
k=k->adj; 
} 
j++; 
} 
j=0; 
cout<<"Breadth First Search Results"; 
cout<<"---------------------------"; 
while(qu[j]!=0) 
{ 
cout<< qu[j] << " "; 
j++; 
} 
getch(); 
return; 
} 
// Breadth First Search(BFS) Traversal. 
void dfs() 
{ 
int stack[25],top=1; 
cout<<"Deapth First Search Results"; 
cout<<"---------------------------"; 
p=start; 
while(p!=NULL) 
{ 
p->status=0; 
p=p->next; 
} 
p=start; 
stack[0]=0; 
stack[top]=p->data; 
p->status=1; 
while(1) 
{ 
if(stack[top]==0) 
break; 
p=start; 
while(p!=NULL) 
{ 
if(p->data==stack[top]) 
break; 
p=p->next; 
} 
cout<< stack[top]<<" "; 
top--; 
k=p->adj; 
while(k!=NULL) 
{ 
q=k->next; 
if(q->status==0) 
{ 
top++; 
stack[top]=q->data; 
q->status=1; 
} 
k=k->adj; 
} 
} 
getch(); 
return; 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
Program Limitations

This program Only process single digit operations 
 Can't handle unary operation 
Only process left to right associativity
#include< iostream >
#include< cmath > 
#include< cstdlib > 
#include< string > 
#define MAX_SIZE 20 
using namespace std; 
template< class T > 
class Stack 
{ 
private: 
T item[MAX_SIZE]; 
int top; 
public: 
Stack() 
{ 
top = -1; 
} 
void push(T data) 
{ 
if(!this->is_full()) 
item[++top] = data; 
else 
{ 
cout<<"Stack Error"<< endl; 
exit(10); 
} 
} 
T pop() 
{ 
if(!this->is_empty()) 
return item[top--]; 
else 
{ 
cout<<"Stack is Empty"<< endl; 
exit(11); 
} 
} 
int size() 
{ 
return top+1; 
} 
bool is_empty() 
{ 
if(top==-1) 
return true; 
else 
return false; 
} 
bool is_full() 
{ 
if(top==MAX_SIZE-1) 
return true; 
else 
return false; 
} 
void display() 
{ 
for(int i=0; i< this->size(); i++) 
{ 
cout<< item[i]<<" "; 
} 
cout<< endl; 
} 
T return_top() 
{ 
return item[top]; 
} 
}; 
class Convert 
{ 
private: 
bool num_flag; 
bool two_digit_flag; 
public: 
Convert(); 
string return_with_bracket(string infix); 
void to_Postfix(string infix,char postfix[]); 
bool prcd(char op1, char op2); 
int isOperand(char op); 
int isOperator(char op); 
bool return_flag()
{ 
return num_flag; 
} 
}; 
Convert::Convert() 
{
this->num_flag = false; 
this->two_digit_flag = false; 
} 
string Convert::return_with_bracket(string infix) 
{ 
return("(" + infix + ")"); 
}
bool Convert::prcd(char op1, char op2) 
{ 
if((op1=='+' || op1=='-' || op1=='*' || op1=='/') && op2=='(' ) 
return true; 
if(op1=='+' && op2=='+') 
return true; 
if(op1=='-' && op2=='-') 
return false; 
if(op1=='-' && op2=='+') 
return false; 
if(op1=='+' && op2=='-') 
return false; 
if(op1=='/' && op2=='/') 
return false; 
if(op1=='/' && (op2=='-' || op2=='+')) 
return true; 
if(op1=='*' && (op2=='+' || op2=='-')) 
return true; 
if((op1 == '-' || op1 == '+') && (op2 =='*' || op2 == '/')) 
return false; 
if((op1 == '#39; || op1 == '+') && (op2 =='*' || op2 == '/' || op2=='-')) 
return true; 
if((op1 == '-' || op1 == '+' || op1 =='*' || op1 == '/')&& op2=='^') 
return false; 
if(op1 == '^' && ( op2 == '+' || op2 =='*' || op2 == '/' || op2=='-')) 
return false; 
} 
int Convert::isOperand(char op) 
{ 
return(op>= '0' && op <= '9'); 
} 
int Convert::isOperator(char op) 
{ 
return(op=='+' || op=='-' || op == '/' || op=='*' || op=='^'); 
} 
void Convert::to_Postfix(string infix, char postfix[]) 
{ 
int position, outpos=0; 
char c; 
int count = 0; 
char temp; 
char stacktop ; 
Stack < char > stack; 
for(position = 0; (c = infix[position])!='\0'; position++) 
{ 
if(this->isOperand(c)) 
{ 
postfix[outpos++] = c; 
this->num_flag = true; 
count++; 
if(count>=2) 
{ 
this->two_digit_flag = true; 
} 
} 
else if(this->isOperator(c)) 
{ 
count = 0; 
if(isOperator(infix[position]) && isOperator(infix[position+1])) 
{ 
cout<<"\aMissing argument in between "<< infix[position]<<" and "<< infix[position+1] 
<<" in column "<< position+1<< endl; 
exit(9); 
} 
if(this->prcd(c, stacktop)) 
{ 
stacktop=stack.return_top(); 
stack.push(c); 
stacktop = c; 
} 
else 
{ 
while(true) 
{ 
temp = stack.pop(); 
postfix[outpos++] =temp; 
stacktop = stack.return_top(); 
if(prcd(c, stacktop) || stacktop=='(') 
break; 
} 
stack.push(c); 
stacktop = stack.return_top(); 
} 
} 
else if(c=='(') 
{ 
count = 0; 
stack.push(c); 
stacktop = stack.return_top(); 
} 
else if(c==')') 
{ 
count = 0; 
while(1) 
{ 
if(stack.size()==0) 
{ 
cout<<"Warning!! Number of ')' is greater than '('" << endl; 
exit(2); 
} 
temp = stack.pop(); 
if(temp!='(') 
{ 
postfix[outpos++] = temp; 
} 
else 
{ 
break; 
}
} 
stacktop =stack.return_top(); 
} 
else 
{ 
cout<<"Invalid input"; 
exit(3); 
} 
if(infix[position]==')' && infix[position+1]=='(') 
{ 
stack.push('*'); 
stacktop = stack.return_top(); 
} 
} 
if(stack.size()!=0) 
{ 
cout<<"Warning!!Number of '(' is greater than ')'"<< endl; 
// exit(6); 
} 
if(!this->return_flag()) 
{ 
cout<<"You must Enter Numeric value for calculation"<< endl; 
cout<<"This program cannot perform operations on variables"; 
exit(5); 
} 
if(this->two_digit_flag) 
{ 
cout<<"Sory! Althoug u may have entered right string"<< endl; 
cout<<"this program is only for single digit operation"<< endl; 
exit(8); 
} 
postfix[outpos] = '\0'; 
} 
class Evaluate 
{ 
public: 
double eval(char expr[], Convert &); 
double oper(int symb, double op1, double op2); 
}; 
double Evaluate::oper(int symb, double op1, double op2) 
{ 
switch(symb) 
{ 
case '+': return (op1 + op2); 
case '-': return (op1 - op2); 
case '*': return (op1 * op2); 
case '/': return (op1 / op2); 
case '^': return (pow(op1, op2)); 
} 
} 
double Evaluate::eval(char expr[],Convert &convert) 
{ 
int c, position; 
char temp1; 
int count = 0; 
double opnd1, opnd2, value; 
Stack< double > stack; 
for(position = 0; (c = expr[position])!='\0'; position++) 
{ 
if(convert.isOperand(c)) 
{ 
temp1 = double(c-'0'); 
stack.push(temp1); 
} 
else 
{ 
opnd2 = stack.pop(); 
if(stack.size()==0) 
{ 
cout<<"This program cannot process unary operation"; 
exit(1); 
} 
opnd1 = stack.pop(); 
value = oper(c, opnd1, opnd2); 
stack.push(value); 
} 
} 
if(stack.size()>=2) 
{ 
cout<<"Sory! this program cannot calculate this"<< endl; 
cout<<"Enter +, *, /, - or ^ between bracket"<< endl; 
exit(4); 
} 
return (stack.pop()); 
} 
int main() 
{ 
Convert convert; 
Evaluate evaluate; 
string bracketted_infix; 
char infix[50], postfix[50]; 
char choice; 
while(1) 
{ 
cout<<"Enter string: "; 
cin>>infix; 
cout<< endl; 
cout<<"Entered String: "<< infix<< endl; 
bracketted_infix = convert.return_with_bracket(infix); 
convert.to_Postfix(bracketted_infix, postfix); 
cout<<"Equivalent Postfix string: "<< postfix<< endl; 
cout<<"RESULT: "; 
cout<< evaluate.eval(postfix, convert); 
cout<<"\nCalculate another string?(y/n) "; 
cin>>choice; 
cout<< endl; 
if(choice=='n') 
break; 
} 
return 0; 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc

what is tree??

In computer science, a tree is a widely used abstract data type (ADT) or data structure implementing this ADT that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes.

Program:

#include <iostream> 
#include < conio.h > 
#include < stdlib.h > 
struct node 
{ 
node *left; 
int value; 
node *right; 
}; 
node *curr=NULL; 
int addnode(node *, node *); 
int inorder(node *); 
int preorder(node *); 
int postorder(node *); 
void main() 
{ 
char c; 
int v; 
clrscr(); 
do 
{ 
cout<<"Select any one"; 
cout<<"0 ->Exit"; 
cout<<"1 ->Add node"; 
cout<<"2 ->Inorder traversal"; 
cout<<"3 ->Preorder traversal"; 
cout<<"4 ->Postorder trversal :"; 
cin>>c; 
switch(c) 
{ 
case '0': 
exit(1); 
case '1': 
node *temp; 
temp = new node; 
cout<<" Enter the value of the node : "; 
cin>>temp->value; 
if(curr==NULL) 
{ 
curr=new node; 
curr->value=temp->value; 
curr->left=NULL; 
curr->right=NULL; 
cout<<" The root node is added"; 
} 
else 
v=addnode(curr,temp); 
if(v==1) 
cout<<" The node is added to the left"; 
else if(v==2) 
cout<<" The node is added to the right"; 
else if(v==3) 
cout<<" The same value exists"; 
break; 
case '2': 
v=inorder(curr); 
if(v==0) 
cout<<"The tree is empty"; 
break; 
case '3': 
v=preorder(curr); 
if(v==0) 
cout<<"The tree is empty"; 
break; 
case '4': 
v=postorder(curr); 
if(v==0) 
cout<<"The tree is empty"; 
break; 
default: 
cout<<"Invalid entry"; 
break; 
}
}
while(c!='0'); 
getch(); 
} 
int addnode(node *fcurr, node *fnew ) 
{ 
if(fcurr->value==fnew->value) 
{ 
return 3; 
} 
else 
{ 
if(fcurr->value > fnew->value) 
{ 
if(fcurr->left != NULL) 
addnode(fcurr->left, fnew); 
else 
{ 
fcurr->left = fnew; 
(fcurr->left)->left=NULL; 
(fcurr->left)->right=NULL; 
return 1; 
} 
} 
else 
{ 
if(fcurr->right != NULL) 
addnode(fcurr->right, fnew); 
else 
{ 
fcurr->right = fnew; 
(fcurr->right)->left=NULL; 
(fcurr->right)->right=NULL; 
return 2; 
} 
} 
} 
} 
int inorder(node *fincurr) 
{ 
if(fincurr == NULL) 
return 0; 
else 
{ 
if(fincurr->left != NULL) 
inorder(fincurr->left); 
cout << fincurr->value<<" "; 
if(fincurr->right != NULL) 
inorder(fincurr->right); 
} 
} 
int preorder(node *fprcurr) 
{ 
if(fprcurr == NULL) 
return 0; 
else 
{ 
cout << fprcurr->value<<" "; 
if(fprcurr->left != NULL) 
preorder(fprcurr->left); 
if(fprcurr->right != NULL) 
preorder(fprcurr->right); 
} 
} 
int postorder(node *fpocurr) 
{ 
if(fpocurr == NULL) 
return 0; 
else 
{ 
if(fpocurr->left != NULL) 
postorder(fpocurr->left); 
if(fpocurr->right != NULL) 
postorder(fpocurr->right); 
cout << fpocurr->value<<" "; 
} 
}
no image
Place where all sort of programming stuff and reviews,technology news are shared and Useful Project of C++,C,java C# etc
# include < conio.h > 
# include < process.h > 
# include < iostream.h > 
# include < alloc.h > 
struct node 
{ 
int ele; 
node *left; 
node *right; 
}; 
typedef struct node *nodeptr; 
class stack 
{ 
private: 
struct snode 
{ 
nodeptr ele; 
snode *next; 
}; 
snode *top; 
public: 
stack() 
{ 
top=NULL; 
} 
void push(nodeptr p) 
{ 
snode *temp; 
temp = new snode; 
temp->ele = p; 
temp->next = top; 
top=temp; 
} 
void pop() 
{ 
if (top != NULL) 
{ 
nodeptr t; 
snode *temp; 
temp = top; 
top=temp->next; 
delete temp; 
} 
} 
nodeptr topele() 
{ 
if (top !=NULL) 
return top->ele; 
else 
return NULL; 
} 
int isempty() 
{ 
return ((top == NULL) ? 1 : 0); 
} 
}; 
class bstree 
{ 
public: 
void insert(int,nodeptr &); 
void del(int,nodeptr &); 
int deletemin(nodeptr &); 
void find(int,nodeptr &); 
nodeptr findmin(nodeptr); 
nodeptr findmax(nodeptr); 
void copy(nodeptr &,nodeptr &); 
void makeempty(nodeptr &); 
nodeptr nodecopy(nodeptr &); 
void preorder(nodeptr); 
void inorder(nodeptr); 
void postorder(nodeptr); 
void preordernr(nodeptr); 
void inordernr(nodeptr); 
void postordernr(nodeptr); 
void leftchild(int,nodeptr &); 
void rightchild(int,nodeptr &); 
}; 
void bstree::insert(int x,nodeptr &p) 
{ 
if (p==NULL) 
{ 
p = new node; 
p->ele=x; 
p->left=NULL; 
p->right=NULL; 
} 
else 
{ 
if (x < p->ele) 
insert(x,p->left); 
else if (x>p->ele) 
insert(x,p->right); 
else 
cout<<"Element already Exits !"; 
} 
} 
void bstree:: del(int x,nodeptr &p) 
{ 
nodeptr d; 
if (p==NULL) 
cout<<"Element not found "; 
else if (x < p->ele) 
del(x,p->left); 
else if (x > p->ele) 
del(x,p->right); 
else if ((p->left == NULL) && (p->right ==NULL)) 
{ 
d=p; 
free(d); 
p=NULL; 
} 
else if (p->left == NULL) 
{ 
d=p; 
free(d); 
p=p->right; 
} 
else if (p->right ==NULL) 
{ 
d=p; 
p=p->left; 
free(d); 
}
else 
p->ele=deletemin(p->right); 
} 
int bstree::deletemin(nodeptr &p) 
{ 
int c; 
if (p->left == NULL) 
{ 
c=p->ele; 
p=p->right; 
return c; 
} 
else 
c=deletemin(p->left); 
return c; 
} 
void bstree::copy(nodeptr &p,nodeptr &p1) 
{ 
makeempty(p1); 
p1=nodecopy(p); 
} 
void bstree::makeempty(nodeptr &p) 
{ 
nodeptr d; 
if (p!=NULL) 
{ 
makeempty(p->left); 
makeempty(p->right); 
d=p; 
free(d); 
p=NULL; 
} 
} 
nodeptr bstree::nodecopy(nodeptr &p) 
{ 
nodeptr temp; 
if (p == NULL) 
return p; 
else 
{ 
temp = new node; 
temp->ele=p->ele; 
temp->left = nodecopy(p->left); 
temp->right = nodecopy(p->right); 
return temp; 
} 
} 
nodeptr bstree::findmin(nodeptr p) 
{ 
if (p==NULL) 
{ 
cout<<"Tree is empty !"; 
return p; 
} 
else 
{ 
while (p->left !=NULL) 
p=p->left; 
return p; 
} 
} 
nodeptr bstree::findmax(nodeptr p) 
{ 
if (p==NULL) 
{ 
cout<<"Tree is empty !"; 
return p; 
} 
else 
{ 
while (p->right !=NULL) 
p=p->right; 
return p; 
} 
} 
void bstree::find(int x,nodeptr &p) 
{
if (p==NULL) 
cout<<"Element not found !"; 
else 
{ 
if (x < p->ele) 
find(x,p->left); 
else if ( x> p->ele) 
find(x,p->right); 
else 
cout<<"Element Found !"; 
} 
} 
void bstree::preorder(nodeptr p) 
{ 
if (p!=NULL) 
{ 
cout<< p->ele<<"-->"; 
preorder(p->left); 
preorder(p->right); 
} 
} 
void bstree::inorder(nodeptr p) 
{ 
if (p!=NULL) 
{ 
inorder(p->left); 
cout<< p->ele<<"-->"; 
inorder(p->right);
} 
} 
void bstree::postorder(nodeptr p) 
{ 
if (p!=NULL) 
{ 
postorder(p->left); 
postorder(p->right); 
cout<< p->ele<<"-->"; 
}

} 
void bstree::preordernr(nodeptr p) 
{ 
stack s; 
while (1) 
{ 
if (p != NULL) 
{ 
cout<< p->ele<<"-->"; 
s.push(p); 
p=p->left; 
} 
else if (s.isempty()) 
{ 
cout<<"Stack is empty"; 
return; 
} 
else 
{ 
nodeptr t; 
t=s.topele(); 
p=t->right; 
s.pop(); 
} 
} 
} 
void bstree::inordernr(nodeptr p) 
{ 
stack s; 
while (1) 
{ 
if (p != NULL) 
{ 
s.push(p); 
p=p->left; 
} 
else 
{ 
if (s.isempty()) 
{ 
cout<<"Stack is empty"; 
return; 
} 
else 
{ 
p=s.topele();
cout<< p->ele<<"-->"; 
} 
s.pop(); 
p=p->right; 
} 
} 
} 
void bstree::postordernr(nodeptr p) 
{ 
stack s; 
while (1) 
{ 
if (p != NULL) 
{ 
s.push(p); 
p=p->left; 
} 
else 
{ 
if (s.isempty()) 
{ 
cout<<"Stack is empty"; 
return; 
} 
else 
if (s.topele()->right == NULL) 
{ 
p=s.topele(); 
s.pop(); 
cout<< p->ele<<"-->"; 
if (p==s.topele()->right) 
{ 
cout<< s.topele()->ele<<"-->"; 
s.pop(); 
} 
} 
if (!s.isempty()) 
p=s.topele()->right; 
else 
p=NULL; 
} 
} 
} 
void bstree::leftchild(int q,nodeptr &p) 
{ 
if (p==NULL) 
cout<<"The node does not exists "; 
else 
if (q < p->ele ) 
leftchild(q,p->left); 
else 
if (q > p->ele) 
leftchild(q,p->right); 
else 
if (q == p->ele) 
{ 
if (p->left != NULL) 
cout<<"Left child of "<< q<<"is "<< p->left->ele; 
else 
cout<<"No Left child !"; 
} 
} 
void bstree::rightchild(int q,nodeptr &p) 
{ 
if (p==NULL) 
cout<<"The node does not exists "; 
else 
if (q < p->ele ) 
rightchild(q,p->left); 
else 
if (q > p->ele) 
rightchild(q,p->right); 
else 
if (q == p->ele) 
{ 
if (p->right != NULL) 
cout<<"Right child of "<< q<<"is "<< p->right->ele; 
else 
cout<<"No Right Child !"; 
} 
} 
int main() 
{ 
int ch,x,leftele,rightele; 
bstree bst; 
char c='y'; 
nodeptr root,root1,min,max; 
root=NULL; 
root1=NULL; 
do 
{ 
// system("clear");
clrscr(); 
cout<<"Binary Search Tree "; 
cout<<"-------------------------"; 
cout<<"1.Insertion 
2.Deletion 
3.NodeCopy"; 
cout<<"4.Find 
5.Findmax 
6.Findmin"; 
cout<<"7.Preorder 
8.Inorder 
9.Postorder"; 
cout<<"10.Leftchild 
11.Rightchild 
0.Exit"; 
cout<<"Enter your choice :"; 
cin>>ch; 
switch(ch) 
{ 
case 1: 
cout<<"1.Insertion"; 
cout<<"Enter the new element to get inserted :"; 
cin>>x; 
bst.insert(x,root); 
cout<<"Inorder traversal is :"; 
bst.inorder(root); 
break; 
case 2: 
cout<<"2.Deletion"; 
cout<<"Enter the element to get deleted :"; 
cin>>x; 
bst.del(x,root); 
bst.inorder(root); 
break; 
case 3: 
cout<<"3.Nodecopy"; 
bst.copy(root,root1); 
cout<<"The new tree is :"; 
bst.inorder(root1); 
break; 
case 4: 
cout<<"4.Find"; 
cout<<"Enter the element to be searched :"; 
cin>>x; 
bst.find(x,root); 
break; 
case 5: 
cout<<"5.Findmax"; 
if (root == NULL) 
cout<<"Tree is empty"; 
else 
{ 
max=bst.findmax(root); 
cout<<"Largest element is : "<< max->ele<< endl; 
} 
break; 
case 6: 
cout<<"6.Findmin"; 
if (root == NULL) 
cout<<"Tree is empty"; 
else 
{ 
min=bst.findmin(root); 
cout<<"Smallest element is : "<< min->ele<< endl; 
} 
break; 
case 7: 
cout<<"7.Preorder"; 
if (root==NULL) 
cout<<"Tree is empty"; 
else 
{ 
cout<<"Preorder traversal (Non-Recursive) is :"; 
bst.preordernr(root); 
cout<<"Preorder traversal (Recursive) is :"; 
bst.preorder(root); 
} 
break; 
case 8: 
cout<<"8.Inorder"; 
if (root==NULL) 
cout<<"Tree is empty"; 
else 
{ 
cout<<"Inorder traversal (Non-Recursive) is :"; 
bst.inordernr(root); 
cout<<"Inorder traversal (Recursive) is :"; 
bst.inorder(root); 
} 
break; 
case 9: 
cout<<"9.Postorder"; 
if (root==NULL) 
cout<<"Tree is empty"; 
else 
{ 
cout<<"Postorder traversal (Non-Recursive) is :"; 
bst.postordernr(root); 
cout<<"Postorder traversal (Recursive) is :"; 
bst.postorder(root); 
} 
break; 
case 10: 
cout<<"10.Finding the left Child "; 
if (root==NULL) 
cout<<"Tree is empty"; 
else 
{ 
cout<<"Enter the node for which the left child is to be found :"; 
cin>>leftele; 
bst.leftchild(leftele,root); 
} 
break; 
case 11: 
cout<<"11.Finding the Right Child "; 
if (root==NULL) 
cout<<"Tree is empty"; 
else 
{ 
cout<<"Enter the node for which the Right child is to be found :"; 
cin>>rightele; 
bst.rightchild(rightele,root); 
} 
break; 
case 0: 
exit(0); 
} 
cout<<"Continue (y/n) ?"; 
cin>>c; 
}
while (c=='y' || c == 'Y'); 
return 0; 
}