Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- using namespace std;
- void push(int x);
- void pop();
- void search(int x);
- typedef struct alvi
- {
- int data;
- struct alvi *next;
- } node;
- node *head=NULL;
- node *tail=NULL;
- int main()
- {
- while(1)
- {
- int choice;
- cout<<"1)push \t 2)pop \t 3)Search \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);
- }
- }
- /*
- node a;
- a.data=10;
- cout<<a.data<<":data";
- */
- return 0;
- }
- void push( int x)
- {
- node *newNode=new node();
- newNode->data=x;
- newNode->next=NULL;
- if(head==NULL)
- {
- newNode->next=NULL;
- head=newNode;
- tail=newNode;
- cout<<"First node pushed\n";
- }
- else
- {
- tail->next=newNode;
- tail=newNode;
- cout<<"value pushesd\n";
- }
- }
- 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 max()
- {
- node *cursor1;
- int maxi=0;
- int maxi2=0;
- while(cursor1!=NULL)
- {
- if(cursor1->data>maxi)
- {
- }
- //cout<<cursor1->data<<"\t";
- cursor1=cursor1->next;
- }
- cout<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement