Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. struct node{
  6. string imie;
  7. string nazwisko;
  8. int nr;
  9. node* next;
  10. node(){
  11. next=0;
  12. }
  13. };
  14.  
  15. struct lista{
  16. node* first;
  17. void wypiszliste();
  18. void dodajdolisty(string im, string naz, int nr);
  19. void usunstudenta(int n);
  20. lista(){
  21. first=0;
  22. }
  23. };
  24.  
  25. void lista::dodajdolisty(string im, string naz, int nr){
  26. node* t=new node;
  27. t->imie=im;
  28. t->nazwisko=naz;
  29. t->nr=nr;
  30. if(first==0) first=t;
  31. else{
  32. node *temp;
  33. temp=first;
  34. while(temp->next){
  35. temp=temp->next;
  36. }
  37. temp->next=t;
  38. t->next=0;
  39. }
  40.  
  41. }
  42. void lista::wypiszliste(){
  43. node* temp;
  44. temp=first;
  45. while(temp){
  46. cout<<temp->imie;
  47. cout<<temp->nazwisko;
  48. cout<<temp->nr;
  49. cout<<endl;
  50. temp=temp->next;
  51. }
  52. }
  53.  
  54. void lista::usunstudenta(int n){
  55. node* temp;
  56. temp=first;
  57. if(n==1) first=temp->next;
  58. else{
  59. int j=0;
  60. while(j+1<n) {
  61. temp=temp->next;
  62. j++;
  63. }
  64. if(temp->next->next==0) temp->next=0;
  65. else temp->next=temp->next->next;
  66. }
  67. }
  68. int main(){
  69. lista *baza=new lista;
  70. baza->dodajdolisty("Mariusz","Kowalski ",302432);
  71. baza->dodajdolisty("Tomasz","Nowak ",302433);
  72. baza->dodajdolisty("Andrzej","Golota ",323932);
  73. baza->usunstudenta(2);
  74. baza->wypiszliste();
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement