Advertisement
Alx09

Untitled

May 6th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned combustibil, k;
  5.  
  6. typedef struct Calls
  7. {
  8. unsigned short x, y, prioritate;
  9. struct Calls * urm;
  10.  
  11. }nevoiasi;
  12. nevoiasi * ADD_Call(nevoiasi *prim) {
  13. nevoiasi *q, *p;
  14. p = (nevoiasi *)malloc(sizeof(nevoiasi));
  15. printf("x= "); scanf("%hu", &p->x);
  16. printf("y= "); scanf("%hu", &p->y);
  17. printf("prioritate= "); scanf("%hu", &p->prioritate);
  18. p->urm = NULL;
  19. if (prim == NULL)
  20. return p;
  21. if (prim->x >= p->x && prim->y > p->y) {
  22. p->urm = prim;
  23. return p;
  24. }
  25. q = prim;
  26. while (q->urm != NULL && q->urm->x <= p->x && q->urm->y < p-> y)
  27. q = q->urm;
  28. p->urm = q->urm;
  29. q->urm = p;
  30. return prim;
  31.  
  32. }
  33. void afisare(nevoiasi *prim) {
  34. nevoiasi *q;
  35. q = prim;
  36. while (q != NULL) {
  37. printf("\n%d %d\n", q->x, q->y);
  38. q = q->urm;
  39. }
  40. }
  41. int main(){
  42. unsigned days = 1, i, n;
  43. nevoiasi *prim = NULL;
  44. do {
  45. printf("Ziua %u:\n", days);
  46. combustibil += 10000;
  47. printf("Numarul de pachete ce pot fi livrate: "); scanf("%u", &k);
  48. printf("Numarul de apeluri: "); scanf("%u", &n);
  49. for (i = 1; i <= n; i++)
  50. prim = ADD_Call(prim);
  51. days++;
  52. } while (1);
  53. system("pause");
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement