SHOW:
|
|
- or go back to the newest paste.
| 1 | #include<iostream> | |
| 2 | #include<cstdio> | |
| 3 | #include<algorithm> | |
| 4 | #include<cstdlib> | |
| 5 | #include<cstring> | |
| 6 | using namespace std; | |
| 7 | ||
| 8 | void push(int x); | |
| 9 | void pop(); | |
| 10 | void search(int x); | |
| 11 | void show(); | |
| 12 | int sb=0; | |
| 13 | int a[100]; | |
| 14 | int s=0; | |
| 15 | typedef struct alvi | |
| 16 | {
| |
| 17 | int data; | |
| 18 | struct alvi *next; | |
| 19 | } node; | |
| 20 | ||
| 21 | node *head=NULL; | |
| 22 | ||
| 23 | int main() | |
| 24 | {
| |
| 25 | while(1) | |
| 26 | {
| |
| 27 | int choice; | |
| 28 | cout<<"1)push \t 2)pop \t 3)Search \t 4)Show \nChoose: "; | |
| 29 | cin>>choice; | |
| 30 | if(choice==1) | |
| 31 | {
| |
| 32 | int input; | |
| 33 | cout<<"Enteer n integer to push: "; | |
| 34 | cin>>input; | |
| 35 | push(input); | |
| 36 | } | |
| 37 | if(choice==2) | |
| 38 | {
| |
| 39 | pop(); | |
| 40 | } | |
| 41 | if(choice==3) | |
| 42 | {
| |
| 43 | int input1; | |
| 44 | cout<<"enter element to search : "<<endl; | |
| 45 | cin>>input1; | |
| 46 | search(input1); | |
| 47 | } | |
| 48 | if(choice==4) | |
| 49 | {
| |
| 50 | show(); | |
| 51 | } | |
| 52 | } | |
| 53 | /* | |
| 54 | node a; | |
| 55 | a.data=10; | |
| 56 | cout<<a.data<<":data"; | |
| 57 | */ | |
| 58 | return 0; | |
| 59 | } | |
| 60 | void push( int x) | |
| 61 | {
| |
| 62 | ||
| 63 | a[s]=x; | |
| 64 | s++; | |
| 65 | node *newNode=new node(); | |
| 66 | newNode->data=x; | |
| 67 | if(head==NULL) | |
| 68 | {
| |
| 69 | newNode->next=NULL; | |
| 70 | head=newNode; | |
| 71 | cout<<"First node pushed\n"; | |
| 72 | sb++; | |
| 73 | } | |
| 74 | else | |
| 75 | {
| |
| 76 | newNode->next=head; | |
| 77 | head=newNode; | |
| 78 | cout<<"value pushesd\n"; | |
| 79 | sb++; | |
| 80 | } | |
| 81 | } | |
| 82 | ||
| 83 | ||
| 84 | void pop() | |
| 85 | {
| |
| 86 | node *cursor; | |
| 87 | cursor=head; | |
| 88 | while(cursor!=NULL) | |
| 89 | {
| |
| 90 | cout<<cursor->data<<"\t"; | |
| 91 | cursor=cursor->next; | |
| 92 | } | |
| 93 | cout<<"\n"; | |
| 94 | } | |
| 95 | void search(int x) | |
| 96 | {
| |
| 97 | node *cursor1; | |
| 98 | cursor1=head; | |
| 99 | int counter=1; | |
| 100 | int flag=0; | |
| 101 | while(cursor1!=NULL) | |
| 102 | {
| |
| 103 | if(cursor1->data==x) | |
| 104 | {
| |
| 105 | flag=1; | |
| 106 | cout<<"element found"<<endl; | |
| 107 | cout<<"the "<<counter<<" th element is : "<<cursor1->data<<endl; | |
| 108 | break; | |
| 109 | } | |
| 110 | //cout<<cursor1->data<<"\t"; | |
| 111 | cursor1=cursor1->next; | |
| 112 | counter++; | |
| 113 | } | |
| 114 | if(flag==0) | |
| 115 | {
| |
| 116 | cout<<"the element "<<x<<" is not found"<<endl; | |
| 117 | } | |
| 118 | cout<<"\n"; | |
| 119 | } | |
| 120 | ||
| 121 | void show() | |
| 122 | {
| |
| 123 | int kk; | |
| 124 | int i , j ,temp; | |
| 125 | for (i = 0; i < sb; i++) | |
| 126 | {
| |
| 127 | for (j = 0; j < (sb - i - 1); j++) | |
| 128 | {
| |
| 129 | if (a[j] > a[j + 1]) | |
| 130 | {
| |
| 131 | temp = a[j]; | |
| 132 | a[j] = a[j + 1]; | |
| 133 | a[j + 1] = temp; | |
| 134 | } | |
| 135 | } | |
| 136 | } | |
| 137 | for(kk=0; kk<sb; kk++) | |
| 138 | {
| |
| 139 | printf("%d ",a[kk]);
| |
| 140 | } | |
| 141 | cout<<endl; | |
| 142 | } |