Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct node
- {
- int a;
- struct node *next;
- };
- struct node* findata(struct node*temp,int x)
- {
- int count=0;
- while(temp->a!=x && temp->next!=NULL)
- {
- count++;
- temp=temp->next;
- }
- if(temp->a==x)
- {
- cout<<"fund at position "<<count+1 <<endl;
- }
- else
- {
- cout<<"not found"<<endl;
- }
- };
- struct node *head=NULL,*temp;
- int main()
- {
- struct node *n1,*n2;
- n1=(struct node*) malloc (sizeof(struct node));
- cout<<"give information for n1"<<endl;
- cin>>n1->a;
- n1->next=NULL;
- head=n1;
- cout<<"give information for n2"<<endl;
- cin>>n2->a;
- n2->next=NULL;
- n1->next=n2;
- int x;
- cout<<"which data u want to find"<<endl;
- cin>>x;
- temp=head;
- findata(temp,x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement