Advertisement
Ruhan_DIU

Untitled

Oct 13th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct node{
  5. int data;
  6. struct node *link;
  7. };
  8.  
  9. struct node *Head=NULL;
  10. struct node *Tail=NULL;
  11.  
  12. void last(int value1){
  13.  
  14. struct node *Node=(struct node*)malloc(sizeof(struct node));
  15. Node->data=value1;
  16. Node->link=NULL;
  17.  
  18. if(Head==NULL){
  19. Head=Node;
  20. Tail=Node;
  21. }else{
  22. Tail->link=Node;
  23. Tail=Node;
  24. }
  25. }
  26.  
  27.  
  28. void first(int value2){
  29. struct node *Node1=(struct node*)malloc(sizeof(struct node));
  30. Node1->data=value2;
  31. Node1->link=NULL;
  32.  
  33. if(Head==NULL){
  34. Head=Node1;
  35. Tail=Node1;
  36. }else{
  37. Node1->link=Head;
  38. Head=Node1;
  39. }
  40. }
  41.  
  42. void search(int value3){
  43. struct node *src=Head;
  44. int count=0;
  45. while(src->link !=NULL){
  46. if(src->data==value3){
  47. count++;
  48. break;
  49. }
  50. src=src->link;
  51. }
  52. if(count==0){
  53. printf("Not found\n");
  54. }else{
  55. printf("found\n");
  56. }
  57. }
  58.  
  59. void display(){
  60. struct node *ptr=Head;
  61. while(ptr->link!=NULL){
  62. printf("%d ",ptr->data);
  63. ptr=ptr->link;
  64. }
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. main(){
  72.  
  73. last(10);
  74. last(20);
  75.  
  76. display();
  77. search(11);
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement