C++ Data Structures

  • Uploaded by: ZEESHAN HAIDER
  • 0
  • 0
  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C++ Data Structures as PDF for free.

More details

  • Words: 469
  • Pages: 6
FROM: IQRA UNIBERSITY ISLAMABAD CAMPUS 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 <process.h> 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 "<<w<<" CHARACTERS: \n"; for(i=0;i<w;i++) { cout<<"CHAR NO "<>word[i]; } char temp; for(i=0;i<SIZE;i++) { temp=word[i]; push(temp); } show();//DISPLAY FUNCTION (OPTIONAL FUNCTION) int v=w-1; int u=w-1; int h=-1; for(i=0;i<w;i++) { if(word[i]==stack[v]) { h++;

} v--; } if(h==u) { cout<<"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<w;i++) { if(stack[i]!='\0') {cout<<stack[i];} } cout<<"\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 ----->"<<curr->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<size;i++) { if(queue[i]!=0) { cout<<" "<
int search; if(rear==0) { cout<<"queue is empty\n"; } cout<<"Enter element to delete "; cin>>search; for(int j=0;j<size;j++) { if(search==queue[j]) { cout<<"ELEMENT FOUND AT POSITION "<<j+1<<"\n"<<"AND HAS BEEN DELETED "<<endl; queue[j]=0; for(int k=0;k<size;k++) { if(j<=k) { queue[k]=0; } }rear--; break; }

} }

Related Documents


More Documents from "SRINIVASA RAO GANTA"

Ccn Lab
November 2019 26
Otdr User Guide
August 2019 25
C++ Data Structures
October 2019 28
13304070_bba.pdf
June 2020 37