Advertisement
Lucky134Lucky

Untitled

Mar 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class LinkedList{
  5. public:
  6.  
  7. LinkedList(int _data){
  8. data=_data;
  9. }
  10.  
  11. void add(int value){
  12. if(next==0) {
  13. LinkedList* d = new LinkedList(value);
  14. d->current = next;
  15. next = d;
  16. }
  17. else {
  18. next->add(value);
  19. }
  20. }
  21.  
  22. void showList(){
  23. if(data == NULL){
  24. cout<<endl<<"Список пуст";
  25. }
  26. if (next == 0){
  27. cout<<data<<" ";
  28. }
  29. else{
  30. cout<<data;
  31. next->showList();
  32. }
  33. }
  34. void putIn(int position, int value){
  35.  
  36. if (position == 1){
  37. LinkedList* d = new LinkedList(value);
  38. d->current = next;
  39.  
  40. LinkedList* c = next;
  41. next = d;
  42. d->next = c;
  43. }
  44. else
  45. next->putIn(position-1, value);
  46. }
  47. void deleteList(int pos){
  48. if (pos == 1){
  49. next = next->next;
  50. delete current;
  51.  
  52. }
  53. else { next->deleteList(pos-1); }
  54.  
  55. }
  56.  
  57. private:
  58. int data = NULL;
  59. LinkedList* next = 0;
  60. LinkedList* current;
  61. };
  62.  
  63. int main()
  64. {
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement