Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include "tlista.h"
  4. #include <stdlib.h>
  5.  
  6. TLista Citire(size_t *lg)
  7. {
  8. TLista L = NULL, aux, u;
  9. TStudent x;
  10. *lg = 0;
  11.  
  12. while( scanf("%s %d", x.nume, &x.nota) != EOF)
  13. {
  14. aux = AlocCelula(x);
  15. if (!aux) return L;
  16. if (!L)
  17. {
  18. L = aux;
  19. u = L;
  20. }
  21. else {
  22. u->urm = aux;
  23. u=aux;
  24. }
  25. *(lg)++;
  26. }
  27.  
  28. return L;
  29. }
  30.  
  31.  
  32. TLista CitireOrdNume(size_t *lg) {
  33. TLista L = NULL,aux,u;
  34. TStudent x;
  35. *lg = 0;
  36. char c;
  37.  
  38. while (scanf("%s %d",x.nume,&x.nota) != EOF) {
  39. aux=AlocCelula(x);
  40. if (!aux) return L;
  41. else {
  42. if (!L || strcmp(x.nume , L->info.nume) < 0) {
  43. if (L) aux->urm = L;
  44. L=aux;
  45. }
  46. else {
  47.  
  48. u = L;
  49. while (u->urm && strcmp(u->urm->info.nume , x.nume) < 0) {
  50. u=u->urm;
  51. }
  52. aux->urm=u->urm;
  53. u->urm = aux;
  54. }
  55.  
  56. }
  57. (*lg)++;
  58.  
  59. }
  60.  
  61. return L;
  62. }
  63.  
  64.  
  65. TLista CitireOrdNote(size_t *lg) {
  66. TLista L = NULL,aux,u;
  67. TStudent x;
  68. *lg = 0;
  69. char c;
  70.  
  71. while (scanf("%s %d",x.nume,&x.nota) != EOF) {
  72. aux=AlocCelula(x);
  73. if (!aux) return L;
  74. else {
  75. if (!L || x.nota < L->info.nota) {
  76. if (L) aux->urm = L;
  77. L=aux;
  78. }
  79. else {
  80.  
  81. u = L;
  82. while (u->urm && u->urm->info.nota < x.nota) {
  83. u=u->urm;
  84. }
  85. aux->urm=u->urm;
  86. u->urm = aux;
  87. }
  88.  
  89. }
  90. (*lg)++;
  91.  
  92. }
  93. while ((c=getchar())!=EOF&&c!= '\n');
  94. return L;
  95. }
  96.  
  97.  
  98.  
  99. int main()
  100. {
  101. TLista x,y;
  102. size_t lx,lg;
  103. y = CitireOrdNote(&lx);
  104. printf("\n");
  105.  
  106. x = CitireOrdNume(&lg);
  107. AfisareL(x);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement