SHARE
TWEET

Untitled

a guest Nov 15th, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <class T> struct Node{
  7.  
  8. public:
  9.  
  10.  T Value;
  11.  
  12.  Node<T> *Next;
  13.  
  14. };
  15.  
  16. template <class T> class T_List{
  17.  
  18.  private:
  19.  
  20.   Node<T> *First;
  21.  
  22.  public:
  23.  
  24.   T_List()
  25.  
  26.   {
  27.  
  28.   First = NULL;
  29.  
  30.   }
  31.  
  32. void Insert(T v){
  33.  
  34.  Node<T> *New_Node = new Node<T>;
  35.  
  36.  New_Node->Value = v;
  37.  
  38.  New_Node->Next = First;
  39.  
  40.  First = New_Node;
  41.  
  42.  }
  43.  
  44. void Show(){
  45.  
  46.     Node<T> *NNode = First;
  47.  
  48.     while (NNode!=NULL)
  49.  
  50.     {
  51.  
  52.     cout<<NNode->Value<<" ";
  53.  
  54.     NNode = NNode->Next;
  55.  
  56.     }
  57.  
  58.     cout<<endl;
  59.  
  60.  
  61.  
  62.  }
  63.  
  64. };
  65.  
  66.  
  67. int main ()
  68.  
  69. {
  70.  
  71.  T_List<int> Object1;
  72.  
  73.  T_List<double> Object2;
  74.  
  75.     T_List<string> Object3;
  76.  
  77.    
  78.  
  79.  Object1.Insert(5);
  80.  
  81.  Object2.Insert(5.659);
  82.  
  83.  Object3.Insert("Beka");
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  Object1.Show();
  90.  
  91.  Object2.Show();
  92.  
  93.  Object3.Show();
  94.  
  95. }
RAW Paste Data
Top