Advertisement
asiffff

link

Feb 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct node
  4. {
  5. int id;
  6. double prize;
  7. struct node *next;
  8. }*start=NULL;
  9.  
  10. void cre()
  11. {
  12. struct node *c,*n;
  13. int a,i;
  14. printf("\nEnter book number:\n");
  15. scanf("%d",&a);
  16. for(i=0;i<a;i++)
  17. {
  18. n=(struct node*)malloc(sizeof(struct node));
  19. printf("Enter book id:\n");
  20. scanf("%d",&n->id);
  21. printf("Enter book prize\n");
  22. scanf("%lf",&n->prize);
  23. n->next=NULL;
  24. if(start == NULL)
  25. {
  26. start=n;
  27. c=n;
  28. }
  29. else
  30. {
  31. c->next = n;
  32. c=n;
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39. void dis()
  40. {
  41. struct node *c;
  42. c=start;
  43. while(c!=NULL)
  44. {
  45. printf("Id-->%d-->%.1lf-->",c->id,c->prize);
  46. c=c->next;
  47. }
  48. printf("NULL");
  49. }
  50. int pos(int a)
  51. {
  52. int po=0,i=0;
  53. struct node *c;
  54. c=start;
  55. while(c!=NULL)
  56. {
  57. po++;
  58. if(c->id == a)
  59. {
  60. return po;
  61. }
  62. c=c->next;
  63. }
  64. return -1;
  65. }
  66. void mid()
  67. {
  68.  
  69. }
  70. void f()
  71. {
  72. struct node *c,*n;
  73. printf("\nEnter a book details at the top:\n Enter Boook Id:\n");
  74. n=(struct node*)malloc(sizeof(struct node));
  75. scanf("%d",&n->id);
  76. printf("Enter prize:\n");
  77. scanf("%lf",&n->prize);
  78. n->next=NULL;
  79. c=start;
  80. n->next=c;
  81. start=n;
  82.  
  83. }
  84. void last()
  85. {
  86. struct node *c,*n;
  87. printf("\nEnter a book details at the last:\n Enter Boook Id:\n");
  88. n=(struct node*)malloc(sizeof(struct node));
  89. scanf("%d",&n->id);
  90. printf("Enter prize:\n");
  91. scanf("%lf",&n->prize);
  92. c=start;
  93. while(c->next != NULL)
  94. {
  95. c=c->next;
  96. }
  97. c->next=n;
  98. n->next=NULL;
  99. }
  100.  
  101. void midb()
  102. {
  103. struct node *c,*n,*t;
  104. printf("\nEnter a book details at mid:\n Enter Boook Id:\n");
  105. n=(struct node*)malloc(sizeof(struct node));
  106. scanf("%d",&n->id);
  107. printf("Enter prize:\n");
  108. scanf("%lf",&n->prize);
  109. int k,po=0;
  110. printf("Before Which Id:\n");
  111. scanf("%d",&k);
  112. po=pos(k);
  113. int i;
  114. c=start;
  115. for(i=0;i<po-2;i++)
  116. {
  117. c=c->next;
  118. }
  119. t=c->next;
  120. n->next=t;
  121. c->next=n;
  122.  
  123. }
  124. void max()
  125. {
  126. struct node *c;
  127. c=start;
  128. double max=0;
  129. while(c!=NULL)
  130. {
  131. if(max<c->prize)
  132. {
  133. max=c->prize;
  134. }
  135. c=c->next;
  136. }
  137. printf("\nHighest prize is %.1lf\n",max);
  138. }
  139. int main()
  140. {
  141. cre();
  142. dis();
  143. f();
  144. dis();
  145. midb();
  146. last();
  147. dis();
  148. max();
  149. int k;
  150. printf("Enter a id to search:\n");
  151. scanf("%d",&k);
  152. int po=pos(k);
  153. if(po>0) printf("Found at %d\n",po);
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement