Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "list.h"
- void List::append(int x) {
- if (_size == 0) {
- first->data = x;
- _size = 1;
- return;
- }
- node *save = last;
- node * new_node = new node;
- last->next = new_node;
- last = new_node;
- last->before = save;
- last->next = nullptr;
- last->data = x;
- _size++;
- }
- List::List() {
- _size = 0;
- first = new node;
- first->data = 0;
- first->next = nullptr;
- last = first;
- }
- int List::get(int index) {
- node *current = first;
- for (int i = 0; i != index; i++) {
- current = current->next;
- }
- return current->data;
- }
- void List::set(int index, int value) {
- node *current = first;
- for (int i = 0; i != index; i++) {
- current = current->next;
- }
- current->data = value;
- }
Add Comment
Please, Sign In to add comment