Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int data[100],link[100];
- int i,n,s,item,ptr;
- cin>>n;
- for(i=1;i<=n;i++)
- {
- cin>>data[i];
- }
- for(i=1;i<=n;i++)
- {
- cin>>link[i];
- }
- cin>>s>>item;
- if(item<data[s])
- {
- cout<<"unsuccessful";
- }
- else
- {
- ptr=s;
- while(ptr!=-1)
- {
- if(item==data[ptr])
- {
- cout<<ptr;
- break;
- }
- else if(item>data[ptr])
- ptr=link[ptr];
- else
- cout<<"unsuccssful";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement