Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Project/Employee Managment Using Link List
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6.  
  7. struct node* createnode(struct node*);
  8. void display(struct node*);
  9. void search(struct node*);
  10.  
  11. struct node
  12. {
  13. char name[10],des[10];
  14. int age;
  15. float salary;
  16. struct node* ptr;
  17. };
  18.  
  19. int main()
  20. {
  21. struct node* head;
  22. int b,i;
  23.  
  24. head=NULL;
  25.  
  26. while(1)
  27. {
  28.  
  29. printf("\n\tEnter the value\n\t1-> to enter the employee details\n\t2->to display the results\n\t3->to search an element\n");
  30. scanf("%d",&b);
  31.  
  32. switch(b)
  33. {
  34. case (1): printf("\n\thow employee details you would like to enter\n");
  35. scanf("%d",&i);
  36. while(i>0)
  37. {
  38. head=createnode(head);
  39. i--;
  40. }
  41. break;
  42.  
  43. case (2): display(head);
  44. break;
  45.  
  46. case (3): search(head);
  47. break;
  48. }
  49. }
  50. }
  51.  
  52.  
  53. void display(struct node* head)
  54. {
  55. if(head==NULL)
  56. {
  57. printf("\n\tThe node is yet to be displayed \n");
  58. }
  59.  
  60. else
  61. {
  62. while(head!=NULL)
  63. {
  64. printf("\n\tThe name of the employee is %s\n",head->name);
  65. printf("\n\tThe designation of the employee is %s\n",head->des);
  66. printf("\n\tThe salary of the employee is %f\n",head->salary);
  67. printf("\n\tThe age of the employee is %d\n",head->age);
  68.  
  69. head=head->ptr;
  70.  
  71. }
  72.  
  73. }
  74. }
  75.  
  76. struct node* createnode(struct node* head)
  77. {
  78.  
  79. struct node* newnode;
  80. newnode=(struct node*)malloc(sizeof (struct node));
  81.  
  82. printf("\n\tEnter the employee name \n");
  83. scanf("%s",newnode->name);
  84. printf("\n\tEnter the employee's designation \n");
  85. scanf("%s",newnode->des);
  86. printf("\n\tEnter the salary of the employee \n");
  87. scanf("%f",&newnode->salary);
  88. printf("\n\tEnter the age of the employee\n");
  89. scanf("%d",&newnode->age);
  90.  
  91. if(newnode == NULL)
  92. {
  93. printf("\n \tEnter the newnode \n");
  94. newnode->ptr=NULL;
  95. }
  96.  
  97. else
  98. {
  99. newnode->ptr=head;
  100.  
  101. }
  102. return newnode;
  103. }
  104.  
  105.  
  106. void search(struct node* head)
  107. {
  108. char ch[10];
  109.  
  110. printf("\n\tEnter the search string\n");
  111.  
  112. scanf("%s",ch);
  113.  
  114.  
  115. while(head!=NULL)
  116. {
  117. if(strcmp(ch,head->des)==0)
  118. {
  119. printf("\n\tThe element is matched\n");
  120. printf("\n\tThe salary of the designated member is %f\n",head->salary);
  121.  
  122. }
  123.  
  124. else {
  125. printf("\n\tThe element is not matched\n");
  126. }
  127. head=head->ptr;
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement