Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<malloc.h>
- struct l_list
- {
- int info;
- struct l_list *next;
- }start, *node;
- int search(int);
- int ptr=0;
- int main()
- {
- int no,i,item,pos;
- //start=(struct l_list *)malloc(sizeof(struct l_list));
- start.next=NULL;
- node=&start;
- printf("How many nodes, you want in linked list? ");
- scanf("%d",&no);
- printf("");
- for(i=0;i<no;i++)
- {
- node->next=(struct l_list *)malloc(sizeof(struct l_list));
- printf("Enter element in node %d: ",i+1);
- scanf("%d",&node->info);
- node=node->next;
- }
- node->next=NULL;
- printf("Linked list(only with info field) is:");
- node=&start;
- while(node->next!=NULL)
- {
- printf("%d ",node->info);
- node=node->next;
- }
- printf("Enter item to be searched : ");
- scanf("%d",&item);
- pos=search(item);
- if(pos>0)
- printf("Your item is found %d times",pos);
- else
- printf("Sorry! item is no in linked list.a");
- printf("%d\n",ptr);
- return 0;
- }
- int search(int item)
- {
- int count=0;
- int n=1;
- node=&start;
- while(node->next!=NULL)
- {
- if(node->info==item)
- {
- count++;
- }
- node=node->next;
- ptr++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement