Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int data;
- struct node* next;
- };
- struct node *head;
- int main()
- {
- head=NULL;
- struct node* temp1=(struct node*)malloc(sizeof(struct node));
- temp1->data=3;
- temp1->next=NULL;
- struct node* temp2=(struct node*)malloc(sizeof(struct node));
- temp2->data=3;
- temp2->next=NULL;
- temp1->next=temp2;
- struct node* temp3=(struct node*)malloc(sizeof(struct node));
- temp3->data=30;
- temp3->next=NULL;
- temp2->next=temp3;
- //adding another
- struct node* temp4=(struct node*)malloc(sizeof(struct node));
- temp4->data=356;
- temp4->next=temp3;
- temp2->next=temp4;
- head=temp1;
- struct node* tempX;
- tempX=head;
- int i,s,flag;
- flag=0;
- i=1;
- printf("Enter the number you want to search: ");
- scanf("%d",&s);
- while (tempX!=NULL)
- {
- if (tempX->data==s)
- {
- printf("found in node %d\n",i);
- flag=1;
- }
- i++;
- tempX=tempX->next;
- }
- if (flag==0)
- {
- printf("Not found in the list\n");
- }
- tempX=head;
- i=1;
- while (tempX!=NULL)
- {
- printf("Output is node %d %d\n",i,tempX->data);
- tempX=tempX->next;
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement