Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //zadanie
  3. /*
  4. struktura zapisująca w każdej osobie imie i wskaźnik do następnej
  5.  
  6.  
  7.  
  8.  
  9. */
  10.  
  11. #include "stdafx.h"
  12. #include <stdio.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include <iostream>
  16. #include <string.h>
  17. //int a;
  18. using namespace std;
  19. int wybor;
  20. bool gra = true;
  21. int kolej = 0;
  22. int ilosc = 0;
  23.  
  24.  
  25. struct osoba
  26. {
  27. char name[20];
  28. struct osoba *next = NULL;
  29. };
  30. struct osoba *first = NULL;
  31. struct osoba *current = NULL;
  32. struct osoba *temp = NULL;
  33. int main()
  34. {
  35. do {
  36. cout << "1.dodaj " << endl;
  37. cout << "2.sprawdz" << endl;
  38. cout << "3.usun" << endl;
  39. cin >> wybor;
  40. system("cls");
  41. switch (wybor)
  42. case 1:
  43.  
  44. {
  45. if (kolej == 0)
  46. {
  47. kolej++;
  48. first = new struct osoba;
  49. current = first;
  50. cin >> first->name;
  51. current->next = temp;
  52. cout << "dodales " << first->name << endl;
  53. ilosc++;
  54. break;
  55.  
  56. }
  57. else;
  58.  
  59.  
  60. temp = new struct osoba;
  61. cin >> temp->name;
  62. current = temp;
  63. cout << "dodales " << temp->name << endl;
  64. current->next = temp;
  65. ilosc++;
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. if (wybor == 2) {
  73.  
  74. current = first;
  75.  
  76. cout << first->name << endl;
  77.  
  78. temp = temp->next;
  79. //current = temp;
  80.  
  81. for ( int i=2; i <ilosc; i++)
  82.  
  83. {
  84.  
  85. cout << current->name << endl;
  86. temp = temp->next;
  87. // current = temp;
  88.  
  89. cout << temp->name << endl;
  90. temp = temp->next;
  91. }
  92. }
  93. } while (first != NULL);
  94. //tworze pierwsza osob
  95. /*
  96. first = new struct osoba;
  97. current = first;
  98. //tworze druga osoba
  99. temp = new struct osoba;
  100. current->next = temp;
  101. current = temp;
  102.  
  103. //tworze trzecia osoba
  104. temp = new struct osoba;
  105. current->next = temp;
  106. current = temp;
  107.  
  108.  
  109. temp = first;
  110. while (temp != NULL)
  111.  
  112. {
  113. cout << temp->name << endl;
  114. temp = temp->next;
  115.  
  116. }
  117.  
  118. //usuwanie
  119. int u = 3;
  120. temp = first;
  121. for (int i = 0; i < u - 2; i++) {
  122.  
  123. temp = temp->next;
  124.  
  125. }
  126.  
  127. /* osoba *current = Lista;
  128. Lista = new osoba;
  129. cout << "podaj imie" << endl;
  130. cin >> a;
  131. Lista -> imie = a;
  132. cout << imie;
  133. current = Lista;
  134. current->next = new osoba;
  135. current = current->next;
  136. current = Lista;
  137. */
  138.  
  139. getchar();
  140. getchar();
  141.  
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement