Advertisement
Guest User

BinNode

a guest
Jan 22nd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 KB | None | 0 0
  1. using System;
  2. //using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Unit4.CollectionsLib;
  7.  
  8. namespace BinNode
  9. {
  10.     class DualChainMain
  11.     {
  12.         public static BinNode<int> CreateBinNodeChain()
  13.         // input: n/a
  14.         // output: returns a reference to an integer BinNode chain
  15.         // assumption: accepts input of numbers untill -999 received
  16.         // Complexity: O(n)
  17.         {
  18.             BinNode<int> dualChain, last, p;
  19.             int num = int.Parse(Console.ReadLine());
  20.  
  21.             dualChain = new BinNode<int>(num);
  22.             last = dualChain;
  23.             num = int.Parse(Console.ReadLine());
  24.  
  25.             while (num != -999)
  26.             {
  27.                 p = new BinNode<int>(num);
  28.                 last.SetRight(p);
  29.                 p.SetLeft(last);
  30.                 last = p;
  31.                 num = int.Parse(Console.ReadLine());
  32.             }
  33.  
  34.             return dualChain;
  35.         }
  36.  
  37.         public static void PrintBinNodeChain(BinNode<int> dualChain)
  38.         // input: a reference to an integer BinNode chain
  39.         // output: prints the chain value following a left to right order
  40.         {
  41.             while (dualChain != null)
  42.             {
  43.                 Console.Write(dualChain);
  44.                 dualChain = dualChain.GetRight();//is that legal? do we lose the head of the chain in main?
  45.             }
  46.         }
  47.  
  48.         public static void PrintReverseBinNodeChain(BinNode<int> dualChain)
  49.         // input: a reference to an integer BinNode chain
  50.         // output: prints the chain value in a reverse order (right to left)
  51.         // complexity: O(n)
  52.         {
  53.             while(dualChain.GetRight()!=null)
  54.             {
  55.                 dualChain = dualChain.GetRight();
  56.             }
  57.             while(dualChain.GetLeft()!=null)
  58.             {
  59.                 Console.WriteLine(dualChain);
  60.             }
  61.            
  62.            
  63.            
  64.            
  65.            
  66.         }
  67.  
  68.         public static bool IsPolindrom(BinNode<char> dualChain)
  69.         // input: a reference to a char BinNode chain
  70.         // output: returns true if the chain is a Polindrom. Otherwise, returns false.
  71.         // complaxity: O(n)
  72.         {
  73.             BinNode<char> Head = dualChain;
  74.             while(dualChain.GetRight()!=null)
  75.             {
  76.                 dualChain = dualChain.GetRight();
  77.             }
  78.             while (dualChain != Head)
  79.             {
  80.                 if (dualChain.GetValue() != Head.GetValue())
  81.                     return false;
  82.                 dualChain = dualChain.GetLeft();
  83.                 Head = Head.GetLeft();
  84.             }
  85.             return true;
  86.         }
  87.  
  88.         public static BinNode<string> TruncateFirstLastWords(BinNode<string> dualChain)
  89.         // input: a reference to a string BinNode chain
  90.         // output: returns a reference to the BinNode chain w/o the first and the last chains
  91.         // complexity: O(n)
  92.         {
  93.             // TODO
  94.             return;
  95.         }
  96.  
  97.         public static BinNode<double> RemoveNumOccurences(BinNode<double> dualChain, double num)
  98.         // input: a reference to real BinNode chain and a real number
  99.         // output: a reference to the BinNode chain w/o chains which their values equal to num
  100.         // complexity: O(n)
  101.         {
  102.             // TODO
  103.             return;
  104.         }
  105.  
  106.         public static int CalcNum(BinNode<int> dualChain)
  107.         // input: a reference to an integer BinNode chain
  108.         // output: an integer number based on the digits appears in the chain
  109.         // example: dualChain -> 3 <-> 0 <-> 8 <-> 5 => num = 3085. assumption: num >= 0
  110.         // complexity: O(n)
  111.         {
  112.             // TODO
  113.             return;
  114.         }
  115.  
  116.         static void Main(string[] args)
  117.         {
  118.             BinNode<int> duList = CreateBinNodeChain();
  119.             PrintBinNodeChain(duList);
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement