Advertisement
Guest User

ho ho ho

a guest
Jan 26th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct lista
  6. {
  7. int liczba;
  8. lista *next;
  9. };
  10.  
  11. int main()
  12. {
  13. lista *poczatek;
  14. lista *temp;
  15. lista *nastepna;
  16. int ile;
  17. cout<<"podaj ilosc liczb"<<endl;
  18. cin>>ile;
  19.  
  20. poczatek = new lista;
  21. poczatek->next = NULL;
  22. cin>>poczatek->liczba;
  23. temp = poczatek;
  24.  
  25. for(int i=1; i<ile; i++)
  26. {
  27.  
  28. nastepna = new lista;
  29. temp->next = nastepna;
  30. cin>>nastepna->liczba;
  31. nastepna->next = NULL;
  32. temp = nastepna;
  33.  
  34. }
  35.  
  36. //wywietla
  37. temp = poczatek;
  38. while(temp)
  39. {
  40. cout<<temp->liczba<<endl;
  41. temp = temp->next;
  42. }
  43.  
  44.  
  45. //usuwa
  46. while(poczatek!=NULL)
  47. {
  48. temp = poczatek;
  49. poczatek = poczatek->next;
  50. delete temp;
  51. }
  52.  
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement