Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class LinkedList{
- public:
- LinkedList(int _data){
- data=_data;
- }
- void add(int value){
- if(next==0) {
- LinkedList* d = new LinkedList(value);
- d->current = next;
- next = d;
- }
- else {
- next->add(value);
- }
- }
- void showList(){
- if(data == NULL){
- cout<<endl<<"Список пуст";
- }
- if (next == 0){
- cout<<data<<" ";
- }
- else{
- cout<<data;
- next->showList();
- }
- }
- void putIn(int position, int value){
- if (position == 1){
- LinkedList* d = new LinkedList(value);
- d->current = next;
- LinkedList* c = next;
- next = d;
- d->next = c;
- }
- else
- next->putIn(position-1, value);
- }
- void deleteList(int pos){
- if (pos == 1){
- next = next->next;
- delete current;
- }
- else { next->deleteList(pos-1); }
- }
- private:
- int data = NULL;
- LinkedList* next = 0;
- LinkedList* current;
- };
- int main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement