Advertisement
asiffff

Untitled

Feb 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. struct student
  5. {
  6. int id;
  7. int cla;
  8. char group[20];
  9. char name[20];
  10. struct student *next,*prev;
  11. }*start=NULL,*end=NULL,*current;
  12.  
  13. void create()
  14. {
  15. if(start==NULL && end==NULL)
  16. {
  17. struct student *new_node;
  18. new_node=(struct student*)malloc(1*sizeof(struct student));
  19. printf("Enter Name:\n");
  20. scanf("%s",&new_node->name);
  21. printf("\nEnter Class:");
  22. scanf("%d",&new_node->cla);
  23. printf("\nEnter ID:");
  24. scanf("%d",&new_node->id);
  25. printf("Enter Group:\n");
  26. scanf("%s",&new_node->group);
  27. new_node->next=NULL;
  28. new_node->prev=NULL;
  29. start=new_node;
  30. end=new_node;
  31. current=new_node;
  32. system("cls");
  33. }
  34. else
  35. {
  36. struct student *new_node;
  37. new_node=(struct student*)malloc(1*sizeof(struct student));
  38. printf("Enter Name:\n");
  39. scanf("%s",&new_node->name);
  40. printf("\nEnter Class:");
  41. scanf("%d",&new_node->cla);
  42. printf("\nEnter ID:");
  43. scanf("%d",&new_node->id);
  44. printf("Enter Group:\n");
  45. scanf("%s",&new_node->group);
  46. new_node->next=NULL;
  47. new_node->prev=NULL;
  48. current->next=new_node;
  49. new_node->prev=current;
  50. end=new_node;
  51. current=new_node;
  52. system("cls");
  53. }
  54. }
  55. struct teacher
  56. {
  57. int id;
  58. char name[20];
  59. struct teacher *next,*prev;
  60.  
  61. }*start1=NULL,*end1=NULL,*current1;
  62. void create1()
  63. {
  64.  
  65. if(start1==NULL && end1==NULL)
  66. {
  67. struct teacher *new_node;
  68. new_node=(struct teacher*)malloc(1*sizeof(struct teacher));
  69. printf("\nEnter the number of teacher id:\n");
  70. scanf("%d",&new_node->id);
  71. printf("\nEnter the teacher name:\n");
  72. scanf("%s",&new_node->name);
  73. new_node->next=NULL;
  74. new_node->prev=NULL;
  75. start1=new_node;
  76. current=new_node;
  77. end1=new_node;
  78.  
  79. }
  80. else
  81. {
  82. struct teacher *new_node;
  83. new_node=(struct teacher*)malloc(1*sizeof(struct teacher));
  84. printf("Enter the number of teacher id:\n");
  85. scanf("%d",&new_node->id);
  86. printf("Enter the teacher name:\n");
  87. scanf("%s",&new_node->name);
  88. new_node->next=NULL;
  89. new_node->prev=NULL;
  90. current->next=new_node;
  91. new_node->prev=current;
  92. current=new_node;
  93. end1=new_node;
  94. }
  95.  
  96. int search(int a)
  97. {
  98. struct student *c;
  99. c=start;
  100. int po=0;
  101. while(c!=NULL)
  102. {
  103. po++;
  104. if(c->id==a)
  105. {
  106. return po;
  107. }
  108. c=c->next;
  109. }
  110. return -1;
  111. }
  112. void dis()
  113. {
  114. struct student *c;
  115. c=start;
  116. while(c!=NULL)
  117. {
  118. printf("\n Name: %s \n ID: %d\n",c->name,c->id);
  119. c=c->next;
  120. }
  121. }
  122. int main()
  123. {
  124. int x;
  125. while(5)
  126. {
  127. printf("\nPress 1 For cre, 2 for Dis,3 search\n");
  128. scanf("%d",&x);
  129. switch(x)
  130. {
  131. case 1:
  132. {
  133. create();
  134. break;
  135. }
  136. case 2:
  137. {
  138. dis();
  139. break;
  140. }
  141. case 3:
  142. {
  143. printf("Enter Id:\n");
  144. int n;
  145. scanf("%d",&n);
  146. int pos = search(n);
  147. if(pos==-1)
  148. {
  149. printf("\n Not Found\n");
  150. }
  151. else
  152. {
  153. struct student *b;
  154. b=start;
  155. int j;
  156. for(j=0;j<pos-1;j++)
  157. {
  158. b=b->next;
  159. }
  160. printf("\nName: %s\n",b->name);
  161. }
  162. }
  163. case 4:
  164. {
  165. create1();
  166. }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement