Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Александр Сулин on 13/01/2018.
- //
- #include <iostream>
- #include "LinkedList.h"
- using namespace std;
- void LinkedList::add(double value) {
- Node *node = root;
- if (node == nullptr) {
- root = new Node(value);
- return;
- }
- while (node->getNext() != nullptr)
- node = node->getNext();
- node->setNext(new Node(value));
- }
- void LinkedList::task1() {
- Node *node = root;
- while (node != nullptr) {
- double temp = node->getValue();
- temp = (temp < 0 ? temp + 1 : temp - 1);
- node->setValue(temp);
- node = node->getNext();
- }
- }
- std::ostream &operator<<(std::ostream &os, const LinkedList &list) {
- Node *node = list.root;
- while (node != nullptr) {
- os << node->getValue() << " ";
- node = node->getNext();
- }
- os << endl;
- return os;
- }
- std::istream &operator>>(std::istream &is, LinkedList &list) {
- int n;
- cout << "n = ";
- is >> n;
- cout << "values = ";
- double temp;
- is >> temp;
- list.setRoot(new Node(temp));
- Node* node = list.root;
- for (int i = 1; i < n; ++i) {
- is >> temp;
- node->setNext(new Node(temp));
- node = node->getNext();
- }
- return is;
- }
- void LinkedList::setRoot(Node *node) {
- this->root = node;
- }
Advertisement
Add Comment
Please, Sign In to add comment