Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- void push(int x);
- void pop();
- void search(int x);
- using namespace std;
- typedef struct alvi
- {
- int data;
- struct alvi *prev;
- struct alvi *next;
- }node;
- node *head=NULL;
- node *tail=NULL;
- int main(void)
- {
- push(1);
- push(2);
- push(3);
- search(10);
- //search(4);
- pop();
- return 0;
- }
- void push(int x)
- {
- node *newNode = new node();
- newNode->data = x;
- if(head==NULL)
- {
- cout<<"First node pushed"<<endl;
- newNode->prev=NULL;
- newNode->next=NULL;
- head=newNode;
- tail=newNode;
- }
- else
- {
- cout<<"other node pushed"<<endl;
- head->prev=newNode;
- newNode->next=head;
- head=newNode;
- //head= newNode;
- }
- }
- void pop()
- {
- node *cursor;
- cursor = tail;
- while(cursor!=NULL)
- {
- cout<<cursor->data;
- cursor=cursor->prev;
- }
- cout<<endl;
- //cout<<cursor->prev->data;
- }
- void search(int x)
- {
- node *cursor1;
- cursor1 = head;
- int flag=0;
- int counter = 1;
- while(cursor1!=NULL)
- {
- if(cursor1->data==x)
- {
- flag=1;
- cout<<"found"<<endl;;
- cout<<"element number : "<<counter<<endl;
- break;
- }
- cursor1=cursor1->next;
- counter++;
- }
- if(flag==0)
- {
- cout<<"not found"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement