コード例 #1
0
ファイル: Program.cs プロジェクト: briannadrew/Ropes
        // Delete
        // Deletes a substring from an existing rope structure from indexes i - j
        public Ropes <T> Delete(int i, int j)
        {
            Ropes <T> splitrope = Split(j); // split the rope at second index

            _ = Split(i);                   // split the rope at first index and discard (what we wanted to delete)
            return(Concatenate(splitrope)); // concatenate the "bookend" ropes back together
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: briannadrew/Ropes
        // Insert
        // Inserts a substring into an existing rope structure at index i
        public Ropes <T> Insert(char[] S, int i)
        {
            int length = 0;

            foreach (char element in S)
            {
                if (element != default(char))
                {
                    length++;       // determine length of S
                }
            }
            Ropes <T> newrope = new Ropes <T>();      // create new rope

            newrope.Rope(S);                          // Create a new rope with the string to be inserted
            Ropes <T> splitrope = Split(i);           // Split current rope at index i

            newrope = newrope.Concatenate(splitrope); // concatenate the new rope of S the the split rope (middle & last)
            return(Concatenate(newrope));             // concatenate the rope to the previously concatenated rope (first & middle)
        }