Guest User

sddsdsds

a guest
Sep 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. struct Osoba
  9. {
  10. char nazwa[20];
  11. struct Osoba *next=NULL;
  12. };
  13.  
  14. int opcja=0;
  15. char pierwszy[20];
  16. char imie[20];
  17. int ilosc=0;
  18. int i=0;
  19.  
  20. int main()
  21. {
  22. struct Osoba *first = NULL;
  23. struct Osoba *current = NULL;
  24. struct Osoba *temp = NULL;
  25. struct Osoba *temp2 = NULL;
  26.  
  27.  
  28. cout << "Podaj imie pierwszej osoby na liscie: ";
  29. cin >> pierwszy;
  30.  
  31. //dodawanie pierwszej osoby
  32. first = new struct Osoba;
  33. strcpy(first->nazwa,pierwszy);
  34.  
  35. current=first;
  36.  
  37. while(true)
  38. {
  39. system("cls");
  40. cout << "1. Dodaj osobe do listy" <<endl;
  41. cout << "2. Wyswietl osoby na liscie" <<endl;
  42. cout << "3. Usun osobe z listy" <<endl<<endl;
  43. cin >> opcja;
  44.  
  45.  
  46. if(opcja==1)
  47. {
  48. system("cls");
  49. //dodawanie kolejnej osoby
  50. cout << "Podaj imie osoby, ktora chcesz dodac: ";
  51. cin >> imie;
  52. temp = new struct Osoba;
  53. strcpy(temp->nazwa,imie);
  54. current->next=temp;
  55. current=temp;
  56. }
  57.  
  58. else if(opcja==2)
  59. {
  60. int i=1;
  61. system("cls");
  62. cout << "Lista:" << endl << endl;
  63. temp=first;
  64. while(temp!=NULL)
  65. {
  66. cout << temp->nazwa<<endl;
  67. temp=temp->next;
  68. }
  69. getchar();
  70. getchar();
  71. }
  72.  
  73. else if(opcja==3)
  74. {
  75. system("cls");
  76. int u;
  77. cout << "Podaj numer osoby: ";
  78. cin >> u;
  79. temp=first;
  80. temp2=first;
  81.  
  82. if(u==1)
  83. {
  84. first=first->next;
  85. delete temp;
  86. }
  87. else
  88. {
  89. for (int i=0;i<u-2;i++)
  90. {
  91. temp = temp->next;
  92. }
  93. temp2 = temp->next;
  94. temp->next = temp->next->next;
  95. delete temp2;
  96. }
  97. }
  98. }
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment