public void AddList() { LinkedListClass list = new LinkedListClass(); list.Add("manju"); list.Add("harish"); list.Add("monoj"); Console.WriteLine(list); }
/// <summary> /// palindrome this instance /// </summary> public void PaliCheck() { LinkedListClass linklist1 = new LinkedListClass(); LinkedListClass linklist2 = new LinkedListClass(); //// creating first queue objects Queue fqueue = new Queue(); //// creating second queue objects Queue squeue = new Queue(); //// take the input from usr Console.WriteLine("ENTER THE STRING"); string s = Console.ReadLine(); int flag = 0; //// string is converting into the tolower and character array char[] strToChar = s.ToLower().ToCharArray(); int lenofchar = strToChar.Length; for (int i = 0; i < lenofchar; i++) { fqueue.Enqueue(strToChar[i]); } for (int i = lenofchar - 1; i >= 0; i--) { squeue.Enqueue(strToChar[i]); } while ((fqueue.Count != 0) && (squeue.Count != 0)) { if ((char)fqueue.Dequeue() != (char)squeue.Dequeue()) { flag++; } } if (flag > 0) { Console.WriteLine("false"); } else { Console.WriteLine("True"); } }
/// <summary> /// this airthmetic expressetion using balance this instance /// </summary> public void Airthexp() { try { int count = 0; //// creating one utility object Utility u = new Utility(); //// creating one stack objects //// Stack<char> sl = new Stack<char>(); LinkedListClass list = new LinkedListClass(); Console.WriteLine("enter expression "); string s1 = Console.ReadLine(); //// string is converting into the charater array char[] ch = s1.ToCharArray(); for (int i = 0; i < ch.Length; i++) { if (ch[i] == '(') { list.Push(ch[i]); } else if (ch[i] == ')') { list.Pop(); } } if (list.Equals(s1)) { Console.WriteLine("Balanced expression"); } else { Console.WriteLine("Expression is not Balance Expressin"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// the add and moving the file /// </summary> public void AddAndRemoveFile() { //// creating the utility object class Utility utility = new Utility(); //// creating the linked list object LinkedListClass ll1 = new LinkedListClass(); LinkedList <string> ll = new LinkedList <string>(); //// creating one file path object string text = File.ReadAllText(utility.FileForUnoderedList()); //// spliting the text in spaces string[] word = text.Split(new char[] { ' ' }); Console.WriteLine("LINKED LIST FILE"); foreach (string list in word) { ll1.AddFirst(list); } ll1.Print(); foreach (string list in ll) { Console.WriteLine(list); } //// check the length of character in text file Console.WriteLine("THE LENGTH CHARATER IN FILE " + text.Length); Console.WriteLine("Enetr the String To the Search in file"); string search = Console.ReadLine(); if (Regex.IsMatch(search.Replace(" ", string.Empty), @"^[a-zA-Z]+$")) { //// searching the element in present in the file if (ll.Contains(search)) { Console.WriteLine("seaching the word contain in file and remove from file"); ll.Remove(search); } else { Console.WriteLine("contain word is not Seaching From File and added in the list"); ll.AddLast(search.Replace(" ", string.Empty)); } } else { Console.WriteLine("FILE ONLY CHARATER AND LETTER ACCEPERD"); } foreach (string list in ll) { Console.WriteLine(list); } string resultStr = string.Join(" ", ll); using (StreamWriter streamWriter = new StreamWriter(utility.ResultForUnderedlist())) { streamWriter.WriteLine(resultStr + " "); } Console.ReadLine(); }
/// <summary> /// Executes the prime anagram queue program /// </summary> public void PrimeAnagramQueueDemo() { try { int[,] primenumbers = new int[10, 50]; int i = 0, j; primenumbers[0, 0] = 0; int[,] anagram = new int[10, 20]; PrimeAnagram pa = new PrimeAnagram(); anagram = pa.PrimeAnagramDemo(); PrimeAnagramClass pac; //// Collection Linked List LinkedList <PrimeAnagramClass> llpac = new LinkedList <PrimeAnagramClass>(); //// Custom Linked list LinkedListClass llc = new LinkedListClass(); for (i = 0; i < 10; i++) { pac = new PrimeAnagramClass(); pac.SetRange(anagram[i, 0]); for (j = 1; anagram[i, j] != 0; j++) { pac.SetAnagrams(anagram[i, j]); } llpac.AddFirst(pac); llc.Enque(pac); } //// for collection linked list for (i = 0; i < 10; i++) { Console.WriteLine("In range {0} - {1} ", llpac.Last.Value.GetRange().ToString(), llpac.Last.Value.GetRange() + 100); int[] ana = llpac.Last.Value.GetAnagrams(); foreach (int inte in ana) { if (inte != 0) { Console.Write(inte + " "); } else { break; } } llpac.RemoveLast(); Console.WriteLine(); } //// for custom linked list Console.WriteLine("****************************For custom linked list**************************************"); for (i = 0; i < 10; i++) { pac = (PrimeAnagramClass)llc.GetLast().GetData(); Console.WriteLine("In range {0} - {1} ", pac.GetRange(), pac.GetRange() + 100); int[] ana = pac.GetAnagrams(); foreach (int inte in ana) { if (inte != 0) { Console.Write(inte + " "); } else { break; } } llc.Deque(); Console.WriteLine(); } } catch (Exception e) { Console.WriteLine("The process is stopped because " + e); } }
public void BalancedParenthesisDemo() { try { //// string to store the expression string expression; Console.WriteLine("Enter the expression"); expression = Console.ReadLine(); //// self implemented Linked list LinkedListClass brackets = new LinkedListClass(); foreach (char c in expression) { //// If open found its pushed switch (c) { case '(': brackets.Push(c); break; //// if closed parenthesis encountered it pops the open parenthesis case ')': switch (brackets.Pop()) { case false: Console.WriteLine("Already empty equation not balanced"); return; } break; case '{': brackets.Push(c); break; case '}': switch (brackets.Pop()) { case false: Console.WriteLine("Already empty equation not balanced"); return; } break; case '[': brackets.Push(c); break; case ']': switch (brackets.Pop()) { case false: Console.WriteLine("Already empty equation not balanced"); return; } break; } //// if stack empty then parenthesis are balanced } if (brackets.IsEmpty()) { Console.WriteLine("The expression is balanced"); } else { Console.WriteLine("The expression is not balanced"); } } catch (Exception e) { Console.WriteLine("Process could noit be comnpleted as " + e); } }