fork download
  1. #include<stdio.h>
  2. struct node
  3. {
  4. int item;
  5. struct node *next
  6. };
  7. int main()
  8. {
  9. struct node *start,*list,*temp;
  10. int i;
  11. int num;
  12. start = (struct node *)malloc(sizeof(struct node));
  13. list = start;
  14. start->next = NULL;
  15. for(i=1;i<5 ;i++)
  16. {
  17. list->item = i;
  18. list->next = (struct node *)malloc(sizeof(struct node));
  19. list = list->next;
  20. }
  21. list->next = NULL;
  22. //printf("Enter the element");
  23. scanf("%d",&num);
  24. temp =start;
  25. while(temp!=NULL)
  26. {
  27. if(temp->item == num)
  28. {
  29. printf("%d is present\n",num);
  30. }
  31. temp = temp->next;
  32. }
  33. if(flag == 0)
  34. {
  35. printf("%d is not present\n",num);
  36. }
  37. printf("Elements of linked lists are:\n");
  38. while(start != NULL)
  39. {
  40. if (start->next == NULL)
  41. {
  42. break;
  43. }
  44. printf("%d\n",start->item);
  45. start = start->next;
  46. }
  47. return 0;
  48. }
  49.  
  50.  
  51.  
Success #stdin #stdout 0s 2428KB
stdin
3
stdout
3 is present
Elements of linked lists are:
1
2
3
4