#include<cstdio>
#include<iostream>
using namespace std;
struct node{
int data;
node *next;
node *last;
node(){int data=0;node *next=NULL;node *last=NULL;}
}*head,*rear;
void append(int x){
node* p=new node;
p->data=x;
p->last=rear->last;
p->last->next=p;
rear->last=p;
p->next=rear;
}
void build(){
head=new node;
rear=new node;
head->next=rear;
rear->last=head;
printf("How many numbers at the beginning:");
int n,x;scanf("%d",&n);
for (;n--;){
scanf("%d",&x);
append(x);
}
}
node* Find(node* head,int x){
node *p=head->next;
for (;p!=NULL;p=p->next){
if (p->data==x)return p;
}
return NULL;
}
char getorder(){
while (1){
printf("Select command and press<Enter>:");
char ch; cin>>ch;
if (ch=='f'||ch=='b'||ch=='q'||ch=='Q')return ch;
puts("Please enter a valid command :");
puts("[b]build a new double link = =");
puts("[f]find x in the link you built");
puts("[Q]uit =======Bazinga!=========");
}
}
bool solve(char ch){
if (ch=='q'||ch=='Q')return 0;
if (ch=='b'){build();}
if (ch=='f'){
printf("Tell me what you want to find:");
int x;scanf("%d",&x);
node *p=new node;
p=Find(head,x);
if (p=NULL)puts("Nowhere to be found");
else printf("%x
",&p);
}
return 1;
}
int main(){
while (solve(getorder())){}
return 0;
}