Skip to content

Commit 73ef726

Browse files
committed
Update output text in AVLTreeTest.cs . Improve PadCenter in Helpers.cs
1 parent 39385b6 commit 73ef726

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

DataStructures/Common/Helpers.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public static string PadCenter(this string text, int newWidth, char fillerCharac
4949
//add a space to the left if the string is an odd number
5050
int padRight = charactersToPad / 2;
5151

52-
StringBuilder resultBuilder = new StringBuilder(newWidth);
53-
for (int i = 0; i < padLeft; i++) resultBuilder.Insert(i, fillerCharacter);
54-
for (int i = 0; i < length; i++) resultBuilder.Insert(i + padLeft, text[i]);
55-
for (int i = newWidth - padRight; i < newWidth; i++) resultBuilder.Insert(i, fillerCharacter);
56-
return resultBuilder.ToString();
52+
return new String(fillerCharacter, padLeft) + text + new String(fillerCharacter, padRight);
5753
}
5854

5955
/// <summary>

MainProgram/DataStructuresTests/AVLTreeTest.cs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static void DoTest()
2222
** 4 5
2323
** \ / \
2424
** 5 ===> 4 7
25-
** \
26-
** 7
25+
** \
26+
** 7
2727
**
2828
***************************************
2929
*/
@@ -65,7 +65,7 @@ public static void DoTest()
6565
// DOUBLE *right* rotation for node 5.
6666
//
6767
// The double rotation is achieved by:
68-
// 1> Simple *left* rotation for node 2, and then
68+
// 1> Simple *left* rotation for node 2, and then
6969
// 2> Simple *right* rotation for node 5
7070
//
7171
/*************************************
@@ -92,7 +92,7 @@ public static void DoTest()
9292
// DOUBLE *right* rotation for node 5.
9393
//
9494
// The double rotation is achieved by:
95-
// 1> Simple *right* rotation for node 7, and then
95+
// 1> Simple *right* rotation for node 7, and then
9696
// 2> Simple *left* rotation for node 5
9797
//
9898
/**************************************************************************
@@ -119,7 +119,7 @@ public static void DoTest()
119119
//
120120
/**************************************************************************
121121
** UNBALANCED ===> TRANSITION (1st R) ===> BALANCED (2nd Rt)
122-
** null .6..
122+
** null .6..
123123
** / \ / \
124124
** 2 6 ===> ===> 2 7
125125
** / \ / \ / \ /
@@ -132,7 +132,7 @@ public static void DoTest()
132132
// ASSERT CASE 5
133133
AssertCase_5(avlTree);
134134

135-
135+
136136
//
137137
// CLEAR THE TREE AND START OVER
138138
// Compare two binary trees with each other (height-wise) using bulk-inserts
@@ -152,56 +152,48 @@ public static void DoTest()
152152

153153
//
154154
// Draw the tree to the console.
155-
Console.WriteLine(String.Format("************\r\n** BST TREE:\r\n************\r\n"));
155+
Console.WriteLine("************\r\n** BST TREE:\r\n************\r\n");
156156
Console.WriteLine(bsTree.DrawTree());
157157

158158
Console.WriteLine("\r\n\r\n");
159159

160-
Console.WriteLine(String.Format("************\r\n** AVL TREE:\r\n************\r\n"));
160+
Console.WriteLine("************\r\n** AVL TREE:\r\n************\r\n");
161161
Console.WriteLine(avlTree.DrawTree());
162162

163163
//
164164
// OUTPUT OF AVL TREE DRAWER
165-
/*****
166-
** ************
167-
** ** AVL TREE:
168-
** ************
169-
** ....15...
170-
** / \
171-
** ...9.. ..20.
172-
** / \ / \
173-
** ..5. 11 16 28
174-
** / \ / \ / \ / \
175-
** 1 7 9 12 19 25 30
176-
** /\ / \ / \ / \ /\ /\ / \
177-
** -1 7 8 10 13 39
178-
** /\ /\ /\ /\ /\ /\
179-
*
165+
/**
166+
** .....15....
167+
** / \
168+
** ...9... .20
169+
** / \ / \
170+
** .5 11 16 28
171+
** / \ / \ \ / \
172+
** 1 7 9 12 19 25 30
173+
** / / \ \ \ \
174+
** -1 7 8 10 13 39
180175
*/
181176

182177

183178
treeDataList = new List<int>() { 15, 25, 5, 12, 1, 9, 7, -1, 11, 30, 8, 10, 13, 28, 39 };
184179
avlTree.Clear();
185180
avlTree.Insert(treeDataList);
186181

187-
Console.WriteLine(String.Format("************\r\n** AVL TREE:\r\n************\r\n"));
182+
Console.WriteLine("************\r\n** AVL TREE:\r\n************\r\n");
188183
Console.WriteLine(avlTree.DrawTree());
189184

190185
//
191186
// OUTPUT OF AVL TREE DRAWER
192-
/*****
193-
**
194-
** .......9......
195-
** / \
196-
** .5 ....12...
197-
** / \ / \
198-
** 1 7 11 .25.
199-
** /\ / \ /\ / \
200-
** -1 8 10 15 30
201-
** /\ /\ /\ /\ / \
202-
** 13 28 39
203-
** /\ /\ /\
204-
**
187+
/**
188+
** ....9...
189+
** / \
190+
** 5 .12.
191+
** / \ / \
192+
** 1 7 11 25
193+
** / \ / / \
194+
** -1 8 10 15 30
195+
** / / \
196+
** 13 28 39
205197
*/
206198

207199
Console.ReadLine();

0 commit comments

Comments
 (0)