Demo entry 6341675

Node.h

   

Submitted by anonymous on Jan 01, 2017 at 13:06
Language: C++. Code size: 1.1 kB.

#pragma once
#include<string>
#include<iostream>

class Base
{
public:
	Base() :next(NULL),type("int"){};
	Base(std::string name) :next(NULL), type(name){ };
	~Base(){};
	virtual void Print() = 0;

	std::string type;
	Base *next;
};


template<typename T>
class  Node : public Base
{
public:
	Node() : Base(), data(0){};
	Node(T in) : data(in), Base(typeid(T).name()){};
	~Node(){};
	
	void Print(){
		std::cout << data<<" ---> ";
	};

private:
	T data;

};

typedef Node<int> Int;
typedef Node<double> Double;
typedef Node<char> Char;
typedef Node<std::string> String;

class List{
public:
	List();
	~List();

	Base *tail;

	//contruct a list
	void newList();
	//traverse a list
	void Traverse();
	//Insert a node
	void InsertN();
	//delete a node
	void deleteN();
		//reverse a list
	void reverse();
	//delete a list
	void deleteL();
	//merge two list
	void mergeL(List &L);
	//cut a part from the list
	List & cutL(List &newList);
	//count the list
	int count();

	int flag;
private:
	Base *head;

};

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).