Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Unit4.CollectionsLib;
- namespace BinNode
- {
- class DualChainMain
- {
- public static BinNode<int> CreateBinNodeChain()
- // input: n/a
- // output: returns a reference to an integer BinNode chain
- // assumption: accepts input of numbers untill -999 received
- // Complexity: O(n)
- {
- BinNode<int> dualChain, last, p;
- int num = int.Parse(Console.ReadLine());
- dualChain = new BinNode<int>(num);
- last = dualChain;
- num = int.Parse(Console.ReadLine());
- while (num != -999)
- {
- p = new BinNode<int>(num);
- last.SetRight(p);
- p.SetLeft(last);
- last = p;
- num = int.Parse(Console.ReadLine());
- }
- return dualChain;
- }
- public static void PrintBinNodeChain(BinNode<int> dualChain)
- // input: a reference to an integer BinNode chain
- // output: prints the chain value following a left to right order
- {
- while (dualChain != null)
- {
- Console.Write(dualChain);
- dualChain = dualChain.GetRight();//is that legal? do we lose the head of the chain in main?
- }
- }
- public static void PrintReverseBinNodeChain(BinNode<int> dualChain)
- // input: a reference to an integer BinNode chain
- // output: prints the chain value in a reverse order (right to left)
- // complexity: O(n)
- {
- while(dualChain.GetRight()!=null)
- {
- dualChain = dualChain.GetRight();
- }
- while(dualChain.GetLeft()!=null)
- {
- Console.WriteLine(dualChain);
- }
- }
- public static bool IsPolindrom(BinNode<char> dualChain)
- // input: a reference to a char BinNode chain
- // output: returns true if the chain is a Polindrom. Otherwise, returns false.
- // complaxity: O(n)
- {
- BinNode<char> Head = dualChain;
- while(dualChain.GetRight()!=null)
- {
- dualChain = dualChain.GetRight();
- }
- while (dualChain != Head)
- {
- if (dualChain.GetValue() != Head.GetValue())
- return false;
- dualChain = dualChain.GetLeft();
- Head = Head.GetLeft();
- }
- return true;
- }
- public static BinNode<string> TruncateFirstLastWords(BinNode<string> dualChain)
- // input: a reference to a string BinNode chain
- // output: returns a reference to the BinNode chain w/o the first and the last chains
- // complexity: O(n)
- {
- // TODO
- return;
- }
- public static BinNode<double> RemoveNumOccurences(BinNode<double> dualChain, double num)
- // input: a reference to real BinNode chain and a real number
- // output: a reference to the BinNode chain w/o chains which their values equal to num
- // complexity: O(n)
- {
- // TODO
- return;
- }
- public static int CalcNum(BinNode<int> dualChain)
- // input: a reference to an integer BinNode chain
- // output: an integer number based on the digits appears in the chain
- // example: dualChain -> 3 <-> 0 <-> 8 <-> 5 => num = 3085. assumption: num >= 0
- // complexity: O(n)
- {
- // TODO
- return;
- }
- static void Main(string[] args)
- {
- BinNode<int> duList = CreateBinNodeChain();
- PrintBinNodeChain(duList);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement