Wednesday, November 12, 2008

Q: Write a program base on user inputs wich performs these three functions:

( 01 ) Check for Plindrome by using stack
( 02 ) convert singlty link list to a doubly link list
( 03 ) Insert elements in queue and then find and delete the target element

#include
#include
void STACK();
void doubly_link_list();
void Qeue();
#define size 100
int queue[size];
int rear=0;
void insert();
void del();
void Show();
const int SIZE=10000;
static char stack[SIZE];
int top=0;
void push(int c);
void show();
int w;
typedef struct item
{
int val;
item*prev;
int data;
item*next;
}item;
void main()
{
int choice;
cout<<"ENTER YOUR CHOICE \n\t1->Plindrome by using stack";
cout<<"\n\t2->Doubly link list \n\t3->Queue\n\t4->exit\n";
cout<<"YOUR CHOICE---> ";
cin>>choice;
while(choice)
{
switch(choice)
{
case 1:STACK();
break;
case 2:doubly_link_list();
break;
case 3:Qeue();
break;
case 4:
exit(0);
break;
default:
cout<<"\nINVALID OPTION!!!!!!!!!!!\n\n"; } cout<<"ENTER YOUR CHOICE \n\t1->Plindrome by using Stack \n\t2->Doubly link list \n\t3->Queue\n\t4-
>exit\n";
cout<<"\tYOUR CHOICE---> ";
cin>>choice;
};
}
////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
void STACK()
{
char word[SIZE];
int i;
cout<<"NUMBER OF CHARACTERS IN YOUR WORDS ARE: "; cin>>w;
cout<<"NOW ENTER WORD OF "<<<" CHARACTERS: \n"; for(i=0;i<<"CHAR NO "<<<" "; cin>>word[i];
}
char temp;
for(i=0;i<<"YES IT IS A PALINDROM\n"; } else { cout<<"NO IT IS NOT A PALINDROM\n"; } } void push(int c) { stack[top]=c; top++; } void show() { if(top<=0) {cout<<"STACK is empty \n";} else cout<<"THE WORD IN STACK IS: "; for(int i=0;i<<<"\n\n"; } //////////////////////////////////////////////// /////////////////////////////////////////////// void doubly_link_list() { int i,n; item*head; item*curr; curr=new item; head=curr; head->next=NULL;
item*link;
link=new item;
link->prev=NULL;
cout<<"Enter numbers of nodes: "; cin>>n;
if(n<=0) { cout<<"NOT POSSIBLE \n"; } else { for(i=1;i<=n;i++) { curr=new item; link=new item; cout<<"ENTER INTEGER: "; cin>>curr->val;
cout<<"\n NODE NUMBER "<<<" \n"; cout<<"BY USING SINGL LINK LIST ----->"<val<<" \n\n"; link->data=curr->val;
cout<<"BY USING DOUBLY LINK LIST----->"<data<<" \n\n"; link->next=link;
link->prev=link->next;
curr->next=curr;
}
curr->next=NULL;
link->next=NULL;
}
}
//////////////////////////////////////////////
//////////////////////////////////////////////
void Qeue()
{
int option;
cout<<"\nENTER 1->Insert 2->Delete 3->Show 4->Go back to main() ";
cin>>option;
while(option)
{
switch(option)
{
case 1:insert();
break;
case 2:del();
break;
case 3:Show();
break;
case 4:main();
break;
default:cout<<"Invalid option!!!"; } cout<<"\nENTER 1->Insert 2->Delete 3->Show 4->Go back to main() ";
cin>>option;
};
}
void insert()
{
if(rear>=(size-1))
{
cout<<"Queue is full\n\n"; } cout<<"Enter element: "; cin>>queue[rear];
if(rear==(size-1))
{
cout<<"\nQueue is full\n\n"; } else rear++; } void Show() { if(rear==0) { cout<<"queue is empty\n"; } else for(int i=0;i<<" "<<<"queue is empty\n"; } cout<<"Enter element to delete "; cin>>search;
for(int j=0;j
{ if(search==queue[j])
{
cout<<"ELEMENT FOUND AT POSITION "<<<"\n"<<"AND HAS BEEN DELETED "<
queue[j]=0;
for(int k=0;k
{
if(j<=k)
{
queue[k]=0;
}
}rear--;
break;
}
}}

No comments: