Untitled

 avatar
unknown
plain_text
16 days ago
936 B
3
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 = nullptr;
	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 intialize(vector<T> vec)
	{
		
		Node<T>* ptr = next;
		int i = 0;
		while (i<vec.size())
		{
			Node<T>& nextt1 = ptr;

			if (ptr == nullptr)
				nextt1 = new Node<T>(vec.at(i));
			else
				nextt1.value = vec.at(i);
			
			ptr = ptr->next;
			i++;
		}
	}

	~Node()
	{
		delete next;
	}
};





int main()
{
	Node<float> root(3.14159);
	root.next = new Node<float>(32.435);
	root.next->next = new Node<float>(5198);
	root.intialize({123, 23, 4, 545 });
	root.GOall();
}
Editor is loading...
Leave a Comment