Advertisement
rootUser

test1.cpp

May 28th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3.  
  4. using namespace std;
  5.  
  6. void push(int x);
  7. void pop();
  8. void search(int x);
  9.  
  10. typedef struct alvi
  11. {
  12.     int data;
  13.     struct alvi *next;
  14. } node;
  15.  
  16. node *head=NULL;
  17. node *tail=NULL;
  18.  
  19. int main()
  20. {
  21.     while(1)
  22.     {
  23.         int choice;
  24.         cout<<"1)push \t 2)pop \t 3)Search \nChoose: ";
  25.         cin>>choice;
  26.         if(choice==1)
  27.         {
  28.             int input;
  29.             cout<<"Enteer n integer to push: ";
  30.             cin>>input;
  31.             push(input);
  32.         }
  33.         if(choice==2)
  34.         {
  35.             pop();
  36.         }
  37.         if(choice==3)
  38.         {
  39.             int input1;
  40.             cout<<"enter element to search : "<<endl;
  41.             cin>>input1;
  42.             search(input1);
  43.         }
  44.     }
  45.     /*
  46.     node a;
  47.     a.data=10;
  48.     cout<<a.data<<":data";
  49.     */
  50.     return 0;
  51. }
  52. void push( int x)
  53. {
  54.     node *newNode=new node();
  55.     newNode->data=x;
  56.     newNode->next=NULL;
  57.     if(head==NULL)
  58.     {
  59.         newNode->next=NULL;
  60.         head=newNode;
  61.         tail=newNode;
  62.         cout<<"First node pushed\n";
  63.     }
  64.     else
  65.     {
  66.         tail->next=newNode;
  67.         tail=newNode;
  68.         cout<<"value pushesd\n";
  69.     }
  70. }
  71.  
  72.  
  73. void  pop()
  74. {
  75.     node *cursor;
  76.     cursor=head;
  77.     while(cursor!=NULL)
  78.     {
  79.         cout<<cursor->data<<"\t";
  80.         cursor=cursor->next;
  81.     }
  82.     cout<<"\n";
  83. }
  84. void  search(int x)
  85. {
  86.     node *cursor1;
  87.     cursor1=head;
  88.     int counter=1;
  89.     int flag=0;
  90.     while(cursor1!=NULL)
  91.     {
  92.         if(cursor1->data==x)
  93.         {
  94.             flag=1;
  95.             cout<<"element found"<<endl;
  96.             cout<<"the "<<counter<<" th element is : "<<cursor1->data<<endl;
  97.             break;
  98.         }
  99.         //cout<<cursor1->data<<"\t";
  100.         cursor1=cursor1->next;
  101.         counter++;
  102.     }
  103.     if(flag==0)
  104.     {
  105.         cout<<"the element "<<x<<" is not found"<<endl;
  106.     }
  107.     cout<<"\n";
  108. }
  109.  
  110. void  max()
  111. {
  112.     node *cursor1;
  113.     int maxi=0;
  114.     int maxi2=0;
  115.     while(cursor1!=NULL)
  116.     {
  117.         if(cursor1->data>maxi)
  118.         {
  119.  
  120.  
  121.         }
  122.         //cout<<cursor1->data<<"\t";
  123.         cursor1=cursor1->next;
  124.     }
  125.     cout<<"\n";
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement