Advertisement
Archangelpl

Untitled

Jun 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include<stdio.h>
  4.  
  5.  
  6.  
  7. typedef struct student
  8. {
  9. char imie[20];
  10. char nazwisko[30];
  11. int rok;
  12. char adres[40];
  13. char kod[10];
  14. double stypendium;
  15. struct student *p;
  16. struct student *n;
  17.  
  18.  
  19. }STUDENT;
  20.  
  21. STUDENT* sortuj(STUDENT* B)
  22. {
  23. if (B == NULL)
  24. {
  25. return B;
  26. }
  27.  
  28. STUDENT* naj = B;
  29. STUDENT* tmp = B;
  30. while (tmp->n != NULL)
  31. {
  32. tmp = tmp->n;
  33. if (naj->stypendium > tmp->stypendium)
  34. {
  35. naj = tmp;
  36. }
  37. }
  38.  
  39. tmp = naj->n;
  40. naj->n = B->n;
  41. B -> n = tmp;
  42. tmp = naj->p;
  43. naj->p = B->p;
  44. B->p = tmp;
  45.  
  46. sortuj(naj->n);
  47.  
  48. return naj;
  49. }
  50.  
  51. FILE *fd;
  52.  
  53. int _tmain(int argc, _TCHAR* argv[])
  54. {
  55.  
  56.  
  57. fd = fopen("dane.txt", "r");
  58. int n = 5;
  59. STUDENT *H, *T, **B, *P, *NAJ,*k;
  60.  
  61.  
  62. for (int i = 0; i < n; i++)
  63. {
  64. B =malloc(sizeof(STUDENT));
  65. fscanf(fd, "%s%s%d%s%s%lf", B[i]->imie, B[i]->nazwisko, &B[i]->rok, B[i]->adres, B[i]->kod, &B[i]->stypendium);
  66.  
  67. if (i == 0)
  68. {
  69. B[i]->p = (STUDENT*)0;
  70. H = B[i];
  71.  
  72. }
  73.  
  74.  
  75. if (i > 0)
  76. {
  77. B[i]->p = P;
  78. P->n = B[i];
  79. }
  80.  
  81. if (i == n - 1)
  82. {
  83. B[i]->p = P;
  84. B[i]->n = (STUDENT*)0;
  85. T = B;
  86. }
  87.  
  88. P = B;
  89.  
  90. B[i] = malloc(sizeof(STUDENT));
  91. fscanf(fd, "%s%s%d%s%s%lf", B[i]->imie, B[i]->nazwisko, &B[i]->rok, B[i]->adres, B[i]->kod, &B[i]->stypendium);
  92. k=sortuj(B);
  93. printf("%s%s%d%s%s%lf", k->imie, k->nazwisko, k->rok, k->adres, k->kod, k->stypendium);
  94. }
  95.  
  96.  
  97. system("PAUSE");
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement