}// END OF GET ROPE STRING /*------------------------------------------------ | | Name: ReBalance | | Description: Quick way of rebalancing rope | | ** Does not rebalance in the way described | in online papers. Retrieves full text | builds a new rope | | ------------------------------------------------*/ public void ReBalance() { Rope rebalance = new Rope(GetRopeString(root.Left, "")); root = rebalance.root; } // END OF REBALANCE
static void Main() { // READ IN A FILE // USE AS TEXT INPUT FOR ROPE string fileName = @"input.txt"; string input = File.ReadAllText(fileName); /* ------------------ | ROPE 1 |------------------*/ Console.WriteLine("\n\t------------------------------------------------------"); Console.WriteLine("\t----------------------- ROPE 1 -----------------------"); Console.WriteLine("\t------------------------------------------------------"); Rope r1 = new Rope("I_love_both_my_cats_"); // *********** // ** PRINT ** // *********** Console.WriteLine("\n-----------------"); Console.WriteLine("----- PRINT -----"); Console.WriteLine("-----------------"); r1.Print(); Console.ReadKey(); // ************* // ** CHAR AT ** // ************* Console.WriteLine("\n-------------------"); Console.WriteLine("----- CHAR AT -----"); Console.WriteLine("-------------------"); Console.WriteLine("\t {0}", r1.CharAt(7)); Console.ReadKey(); /* ------------------ | ROPE 2 |------------------*/ Console.WriteLine("\n\t------------------------------------------------------"); Console.WriteLine("\t----------------------- ROPE 2 -----------------------"); Console.WriteLine("\t------------------------------------------------------"); Rope r2 = new Rope("because_they_are_so_fluffy"); // *********** // ** PRINT ** // *********** Console.WriteLine("\n-----------------"); Console.WriteLine("----- PRINT -----"); Console.WriteLine("-----------------"); r2.Print(); Console.ReadKey(); // *************** // ** SUBSTRING ** // *************** Console.WriteLine("\n---------------------"); Console.WriteLine("----- SUBSTRING -----"); Console.WriteLine("---------------------"); // FIRST LEAF Console.WriteLine("\t {0}", r2.Substring(2, 4)); Console.ReadKey(); // FIRST --> SECOND LEAF Console.WriteLine("\t {0}", r2.Substring(3, 8)); Console.ReadKey(); // SECOND LEAF Console.WriteLine("\t {0}", r2.Substring(8, 12)); Console.ReadKey(); // SECOND --> THIRD LEAF Console.WriteLine("\t {0}", r2.Substring(11, 17)); Console.ReadKey(); // THIRD LEAF Console.WriteLine("\t {0}", r2.Substring(13, 15)); Console.ReadKey(); // THIRD --> FOURTH LEAF Console.WriteLine("\t {0}", r2.Substring(17, 23)); Console.ReadKey(); // FIRST --> FOURTH LEAF Console.WriteLine("\t {0}", r2.Substring(3, 23)); Console.ReadKey(); // NOT IN ROPE Console.WriteLine("\t {0}", r2.Substring(3, 27)); Console.ReadKey(); // SINGLE CHARACTER Console.WriteLine("\t {0}", r2.Substring(3, 3)); Console.ReadKey(); /* ------------------ | ROPE 3 |------------------*/ Console.WriteLine("\n\t------------------------------------------------------"); Console.WriteLine("\t----------------------- ROPE 3 -----------------------"); Console.WriteLine("\t------------------------------------------------------"); Rope r3 = new Rope("ROPE_3"); // ***************** // ** CONCATENATE ** // ***************** Console.WriteLine("\n-----------------------"); Console.WriteLine("----- CONCATENATE -----"); Console.WriteLine("-----------------------"); r3.root.Left = r3.Concatenate(r1.root.Left, r2.root.Left); r3.root.Left.SubLength = r1.root.SubLength; r3.root.SubLength = r3.root.Left.SubLength + r2.root.SubLength; Console.WriteLine("\n... CONCATENATE R1 AND R2 ..."); r3.Print(); Console.ReadKey(); // ************ // ** INSERT ** // ************ Console.WriteLine("\n------------------"); Console.WriteLine("----- INSERT -----"); Console.WriteLine("------------------"); if (r3.Insert("AND_MY_DOG_", 20)) { Console.WriteLine("\n... INSERTED 'AND_MY_DOG_' INTO ROPE 3 ..."); r3.Print(); } else { Console.WriteLine("\n... INSERT FAILED ..."); } Console.ReadKey(); // *************** // ** REBALANCE ** // *************** r3.ReBalance(); // ************ // ** DELETE ** // ************ Console.WriteLine("\n------------------"); Console.WriteLine("----- DELETE -----"); Console.WriteLine("------------------"); if (r3.Delete(30, 43)) { Console.WriteLine("\n... DELETED A SUBSTRING FROM ROPE 3 ..."); r3.Print(); } else { Console.WriteLine("\n... DELETE FAILED ..."); } Console.ReadKey(); /* ------------------ | ROPE 4 |------------------*/ Console.WriteLine("\n\t------------------------------------------------------"); Console.WriteLine("\t----------------------- ROPE 4 -----------------------"); Console.WriteLine("\t------------------------------------------------------"); // ROPE CREATED WITH INPUT FROM A TEXT FILE // 3910 CHARACTERS Rope r4 = new Rope(input); // *********** // ** PRINT ** // *********** Console.WriteLine("\n-----------------"); Console.WriteLine("----- PRINT -----"); Console.WriteLine("-----------------"); r4.Print(); Console.ReadKey(); // *********** // ** SPLIT ** // *********** Console.WriteLine("\n-----------------"); Console.WriteLine("----- SPLIT -----"); Console.WriteLine("-----------------"); r4.Split(457); Console.ReadKey(); // *************** // ** REBALANCE ** // *************** r4.ReBalance(); // ************ // ** INSERT ** // ************ Console.WriteLine("\n------------------"); Console.WriteLine("----- INSERT -----"); Console.WriteLine("------------------"); if (r4.Insert(" -----Procuring education on consulted assurance in do----- ", 234)) { Console.WriteLine("\n... INSERTED ' -----Procuring education on consulted assurance in do----- ' INTO ROPE 3 ..."); r4.Print(); } else { Console.WriteLine("\n... INSERT FAILED ..."); } Console.ReadKey(); Console.WriteLine(); } // END OF MAIN