#include <bits/stdc++.h>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
}Node;
Node *getNewNode(int val){
Node *p=(Node*)malloc(sizeof(Node));
p->data=val;
p->next=p;
return p;
}
Node *insert(Node *head,int pos,int val){
if(pos==0){
Node *p=getNewNode(val);
p->next=head;
return p;
}
Node *p=head;
for(int i=1;i<pos;i++)p=p->next;
Node *node=getNewNode(val);
node->next=p->next;
p->next=node;
return head;
}
void clear(Node *head){
if(head==NULL)return ;
for(Node *p=head,*q;p;p=q){
q=p->next;
free(p);
}
return ;
}
void output_linklist(Node *head){
int n=0;
for(Node *p=head;p;p=p->next)n+=1;
for(int i=0;i<n;i++){
cout<<i<<" ";
}
cout<<endl;
for(Node *p=head;p;p=p->next){
cout<<p->data<<"->";
}
cout<<endl<<endl<<endl;
return ;
}
int find(Node* head,int val){
Node* p=head;
int n=0;
while(p){
if(p->data==val){
output_linklist(head);
int len=n*4;
for(int i=0;i<len;i++){
cout<<" ";
}
cout<<"^\n";
for(int i=0;i<len;i++){
cout<<" ";
}
cout<<"|\n";
return 1;
}
n++;
p=p->next;
}
return 0;
}
int main(){
srand(time(0));
#define MAX_OP 5
Node *head=NULL;
for(int i=0;i<MAX_OP;i++){
int pos=rand()%(i+1),val=rand()%100,ret;
cout<<"insert "<<pos<<" at "<<val<<"|";
head=insert(head,pos,val);
output_linklist(head);
}
int val;
while(cin>>val){
if(!find(head,val)){
cout<<"not found\n";
}
}
clear(head);
return 0;
}