Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include "Operacje.h"
  2. #include <stdlib.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. struct STRUKTURA
  8. {
  9. double double1;
  10. double double2;
  11. double double3;
  12. int liczba;
  13. struct STRUKTURA* nast;
  14. struct STRUKTURA* wcze;
  15. };
  16.  
  17. void Operacje::inicjacja() {
  18. struct STRUKTURA* strukura;
  19. strukura = (struct STRUKTURA*)malloc(sizeof(struct STRUKTURA));
  20. strukura->nast = NULL;
  21. Operacje::struktura = strukura;
  22. }
  23.  
  24. struct STRUKTURA* Operacje::adres() {
  25. return Operacje::struktura;
  26. }
  27.  
  28. void Operacje::dodajElement(int element) {
  29. struct STRUKTURA* tmp = Operacje::struktura;
  30. struct STRUKTURA* tmp2;
  31. if (Operacje::struktura->nast == NULL)
  32. {
  33. tmp->double1 = 1;
  34. tmp->double2 = 1;
  35. tmp->double3 = 1;
  36. tmp->liczba = element;
  37. tmp->nast = tmp;
  38. tmp->wcze = tmp;
  39. }
  40. else {
  41. struct STRUKTURA* nowy;
  42. nowy = (struct STRUKTURA*)malloc(sizeof(struct STRUKTURA));
  43. do
  44. {
  45. if (tmp == Operacje::struktura) {
  46. nowy->double1 = (rand() % 100);
  47. nowy->double2 = (rand() % 1000) + 101;
  48. nowy->double3 = (rand() % 10000) + 1001;
  49. nowy->liczba = element;
  50. nowy->nast = Operacje::struktura;
  51. nowy->wcze = tmp;
  52. tmp->nast = nowy;
  53. Operacje::struktura->wcze = nowy;
  54. }
  55. tmp = tmp->nast;
  56. } while (tmp != Operacje::struktura);
  57. }
  58. }
  59.  
  60. void Operacje::wyswietlElementy() {
  61. struct STRUKTURA* tmp = Operacje::struktura;
  62. do
  63. {
  64. cout << tmp->liczba;
  65. tmp = tmp->nast;
  66. if (tmp == Operacje::struktura)
  67. break;
  68. } while (tmp != tmp->nast);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement