Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///find
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int data;
- struct node *next;
- };
- int main()
- {
- struct node *prev,*head,*p;
- int n,i;
- scanf("%d",&n);
- head=NULL;
- for(i=0;i<n;i++)
- {
- p=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&p->data);
- p->next=NULL;
- if(head==NULL){
- head=p;
- }
- else{
- prev->next=p;
- }
- prev=p;
- }
- struct node* ptr;
- ptr=head;
- int dat;
- printf("Enter data");
- scanf("%d",&dat);
- i=0;
- while(ptr!=NULL){
- ++i;
- if(ptr->data==dat){
- printf("Found position at: %d\n",i);
- break;
- }
- ptr=ptr->next;
- }
- if(ptr==NULL)
- {
- printf("Not found\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement