Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- void push(int x);
- void pop();
- void search(int x);
- void show();
- int sb=0;
- int a[100];
- int s=0;
- typedef struct alvi
- {
- int data;
- struct alvi *next;
- } node;
- node *head=NULL;
- int main()
- {
- while(1)
- {
- int choice;
- cout<<"1)push \t 2)pop \t 3)Search \t 4)Show \nChoose: ";
- cin>>choice;
- if(choice==1)
- {
- int input;
- cout<<"Enteer n integer to push: ";
- cin>>input;
- push(input);
- }
- if(choice==2)
- {
- pop();
- }
- if(choice==3)
- {
- int input1;
- cout<<"enter element to search : "<<endl;
- cin>>input1;
- search(input1);
- }
- if(choice==4)
- {
- show();
- }
- }
- /*
- node a;
- a.data=10;
- cout<<a.data<<":data";
- */
- return 0;
- }
- void push( int x)
- {
- a[s]=x;
- s++;
- node *newNode=new node();
- newNode->data=x;
- if(head==NULL)
- {
- newNode->next=NULL;
- head=newNode;
- cout<<"First node pushed\n";
- sb++;
- }
- else
- {
- newNode->next=head;
- head=newNode;
- cout<<"value pushesd\n";
- sb++;
- }
- }
- void pop()
- {
- node *cursor;
- cursor=head;
- while(cursor!=NULL)
- {
- cout<<cursor->data<<"\t";
- cursor=cursor->next;
- }
- cout<<"\n";
- }
- void search(int x)
- {
- node *cursor1;
- cursor1=head;
- int counter=1;
- int flag=0;
- while(cursor1!=NULL)
- {
- if(cursor1->data==x)
- {
- flag=1;
- cout<<"element found"<<endl;
- cout<<"the "<<counter<<" th element is : "<<cursor1->data<<endl;
- break;
- }
- //cout<<cursor1->data<<"\t";
- cursor1=cursor1->next;
- counter++;
- }
- if(flag==0)
- {
- cout<<"the element "<<x<<" is not found"<<endl;
- }
- cout<<"\n";
- }
- void show()
- {
- int kk;
- int i , j ,temp;
- for (i = 0; i < sb; i++)
- {
- for (j = 0; j < (sb - i - 1); j++)
- {
- if (a[j] > a[j + 1])
- {
- temp = a[j];
- a[j] = a[j + 1];
- a[j + 1] = temp;
- }
- }
- }
- for(kk=0; kk<sb; kk++)
- {
- printf("%d ",a[kk]);
- }
- cout<<endl;
- }
Add Comment
Please, Sign In to add comment