#include <iostream> // basic i/o
#include <cstdlib> // rand() and srand()
#include <ctime> // system time
#include <string>
#include <fstream>
using namespace std;

struct Node{
	int value;
	Node* next;
};

int nodeSum(Node* current){
	int total = 0;
	while (current->next != nullptr){
		total += current->value;
		current = current->next;
	}
	total += current->value;
	return total;
}

int main(){
	Node a,b,c;
	Node d,e,f;
	Node* first = nullptr;

	a.value = 1;
	b.value = -1;
	c.value = 2;
	
	a.next = &b;
	b.next = &c;
	c.next = nullptr;
	
	first = &a;
	
	cout << "Node a:\naddress: " << &a << ", value: " << a.value << ", next address: " << a.next << endl;
	cout << "Node b:\naddress: " << &b << ", value: " << b.value << ", next address: " << b.next << endl;
	cout << "Node c:\naddress: " << &c << ", value: " << c.value << ", next address: " << c.next << endl;

	cout << "Sum of the first List (a,b,c): " << nodeSum(first) << endl;

	d.value = 1;
	e.value = 0;
	f.value = -1;

	first = &f;

	f.next = &e;
	e.next = &d;
	d.next = nullptr;

	cout << "Node d:\naddress: " << &d << ", value: " << d.value << ", next address: " << d.next << endl;
	cout << "Node e:\naddress: " << &e << ", value: " << e.value << ", next address: " << e.next << endl;
	cout << "Node f:\naddress: " << &f << ", value: " << f.value << ", next address: " << f.next << endl;

	cout << "Sum of the second List (f,e,d): " << nodeSum(first) << endl;

	return 0;
}