Untitled

 avatar
unknown
plain_text
a month ago
957 B
5
Indexable
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
using namespace std;


template <typename T> class Node
{
public:
	T value = 0;
	Node<T>* next = nullptr;
	Node<T>* last = this;

public:
	Node(T val)
	{
		value = val;
	}

	void GOall()
	{
		cout << value << "\n";
		Node<T>* ptr = next;

		while (ptr != nullptr)
		{
			cout << ptr->value << "\n";
			ptr = ptr->next;
		}
	}

	void initialiseLast(T elem)
	{
		last->next = new Node<T>(elem);
		last = last->next;
	}

	void initialiseBeforeR(T elem)
	{
		Node<T>* ptr = new Node<T>(0);
		*ptr = *this;
		next = ptr;
		value = elem;
	}

	~Node()
	{
		delete next;
	}

};



int main()
{
	Node<float>* root = new Node<float>(3.14159);
	root->initialiseLast(545);
	root->initialiseLast(23);
	root->initialiseLast(675);
	root->initialiseLast(67);
	root->initialiseBeforeR(69);
	root->GOall();
	cout << root->last->value;
}
Editor is loading...
Leave a Comment