Related
I'm trying to print a right angled triangle with ascending and descending numbers using recursion only.
void straightTriangular(int num)
{
if (num == 0)
{
return;
}
straightTriangular(num - 1);
for (int i = 1; i <= num; i++)
{
cout << i;
}
cout << endl;
}
How can I do this with recursion only without "for" loop?
if the user input number is 4 then
I want the output to be this:
1
121
12321
1234321
my output using the code I posted:
1
12
123
1234
Notice that a triangle(n) has a triangle(n-1) on top of it. It has self-similar structure above it.
Also notice that a layer looking like x...n...x is x (x+1)...n...(x+1) x, which has self-similar structure inside it.
void layer(int x, int n) {
std::cout << x;
if (x >= n) return;
layer(x + 1, n);
std::cout << x;
}
void triangle(int n) {
if (n <= 0) return;
triangle(n - 1);
layer(1, n);
std::cout << std::endl;
}
If you want to render a pyramid with each layer centered, instead of a right-angled triangle, then what appears above a layer is not just a simple triangle, but an indented triangle. You must keep track of this indentation.
The layer function remains the same, but you first print out some space according to the indentation level of the current pyramid.
#include <iostream>
void space(int n) {
if (n <= 0) return;
std::cout << ' ';
space(n-1);
}
void layer(int x, int n) {
std::cout << x;
if (x >= n) return;
layer(x + 1, n);
std::cout << x;
}
void pyramid(int n, int indent) {
if (n <= 0) return;
pyramid(n - 1, indent + 1);
space(indent);
layer(1, n);
std::cout << std::endl;
}
int main() {
pyramid(4, 0);
}
You can have:
a printTriangleRec function that goes on printing every line recursively,
two printAscendingRec and printDescendingRec functions that print the two halves of each line recursively.
[Demo]
#include <iostream> // cout
void printAscendingRec(int cur, int top)
{
std::cout << cur;
if (cur != top)
{
printAscendingRec(cur + 1, top);
}
}
void printDescendingRec(int cur)
{
if (cur)
{
std::cout << cur;
printDescendingRec(cur - 1);
}
}
void printTriangleRec(int cur, int top)
{
printAscendingRec(1, cur);
printDescendingRec(cur - 1);
std::cout << "\n";
if (cur != top)
{
printTriangleRec(cur + 1, top);
}
}
void printTriangle(int num)
{
if (num < 1)
{
std::cout << "Error: num < 1\n";
return;
}
printTriangleRec(1, num);
}
int main()
{
printTriangle(4);
}
I want to print an X shape using n number of rows but without any loop. I have to use a recursive function to print the X.
I have called the functions along with space function but it didn't print the X. It printed:
* *
* *
* *
I have to solve this problem using recursion. No for loop or while loop is allowed to solve this one.
// C++ implementation to print the given
// pattern recursively
#include <bits/stdc++.h>
using namespace std;
// function to print the 'n-th' row of the
// pattern recursively
int g;
void printPatternRowRecur(int n) {
if (n < 1)
return;
if (n = 1) {
cout << "*";
}
// print the remnaining stars of the n-th row
// recursively
else {
return;
}
printPatternRowRecur(n - 1);
}
void print_space(int space) {
// base case
if (space == 0)
return;
cout << " ";
// recursively calling print_space()
print_space(space - 1);
}
int s;
void Rhombus(int n) {
// base condition
if (s >= n)
return;
else {
print_space(s);
printPatternRowRecur(n);
print_space(n - s);
printPatternRowRecur(n);
}
// print the stars of the n-th row
s++;
// move to next line
cout << endl;
// print stars of the remaining rows recursively
Rhombus(n);
}
// Driver program to test above
int main() {
int n = 3;
//cout << "Enter the number of lines you want to print" << endl;
//cin >> n;
//cout << endl << "Rhombus" << endl;
Rhombus(n);
return 0;
}
if (n = 1) should be if (n == 1). As coded, the if expression is always true.
Here is a simplified version:
// C++ implementation to print the given pattern recursively
#include <iostream>
using namespace std;
void print_spaces(int n) {
if (n > 0) {
cout << ' ';
print_spaces(n - 1);
}
}
void rhombus(int s, int n) {
if (s < n) {
int left = min(s, n - s - 1);
int middle = n - 2 * left - 2;
print_spaces(left);
cout << '*';
if (middle >= 0) {
print_spaces(middle);
cout << '*';
}
cout << endl;
// print stars of the remaining rows recursively
rhombus(s + 1, n);
}
}
void rhombi(int s, int n) {
if (s <= n) {
cout << endl << "Rhombus " << s << endl;
rhombus(0, s);
rhombi(s + 1, n);
}
}
int main() {
//int n = 3;
//cout << "Enter the number of lines you want to print" << endl;
//cin >> n;
//cout << endl << "Rhombus" << endl;
//rhombus(0, n);
rhombi(0, 7);
return 0;
}
#include <iostream>
using namespace std;
// * *
// * *
// *
// * *
// * *
//printStarHorizontally will recursively print '*' on a line using x coordinates
void printStarHorizontally(int xCoordinate1, int xCoordinate2, int currentXCoordinate, int maxCoordinate){
if(currentXCoordinate >= maxCoordinate) {
cout<<endl;
return;
}
if(currentXCoordinate == xCoordinate1 || currentXCoordinate == xCoordinate2) {
cout<<"*";
} else {
cout<<" ";
}
printStarHorizontally(xCoordinate1, xCoordinate2, currentXCoordinate + 1, maxCoordinate);
}
//PrintCross will go to each height and then use printStarHorizontally func. to print star on that particular height
void PrintCross(int heightOfCross, int currentHeight) {
if(currentHeight >= heightOfCross) return;
printStarHorizontally(currentHeight, heightOfCross-currentHeight-1, 0, heightOfCross);
PrintCross(heightOfCross,currentHeight+1);
}
int main() {
// heightOfCross should be odd integer
int heightOfCross = 13;
PrintCross(heightOfCross, 0);
return 0;
}
Here's a recursion with one function, one given parameter, and two default parameters:
#include <iostream>
using namespace std;
void f(int y, int x=1, int w=0){
if (y < 1)
return;
if (x > 0){
f(y, -(y + 2 * w), w);
f(y - 2, x, w + 1);
if (y > 1)
f(y, -(y + 2 * w), w);
return;
}
if (x == -w){
cout << endl;
return;
}
if (x == -(w + y) || x == -(w + 1))
cout << '*';
else
cout << ' ';
f(y, x + 1, w);
}
int main(){
f(5);
cout << endl;
f(6);
return 0;
}
I would use two recursive functions: first to write a character after a number of spaces, second to write the lines.
#include <iostream>
/*************************************
* display on character (c) on out after x spaces recursively
* **********************************/
void display_char(int x, std::ostream& out = std::cout, char c='*') {
if (x == 0) out << c;
else {
out << ' ';
display_char(x-1, out, c);
}
}
/*********************************
* displays lines to draw an X pattern
* The pattern is composed of c characters on out
* x decreases to 0 while y increases and a c
* is printed at positions x and y
* ******************************/
void display_line(int x, int y=0, std::ostream& out=std::cout, char c='*') {
int oldx=x, oldy=y;
if (x < y) {
int t = x;
x = y;
y = t;
}
display_char(y, out, c);
if (x != y) display_char(x - y, out, c);
out << '\n';
if (oldx > 0) display_line(oldx-1, oldy+1, out, c);
}
int main() {
int x;
std::cout << "X size (int): ";
std::cin >> x;
display_line(x-1);
return 0;
}
I currently have code that displays a number triangle:
#include <iostream>
using namespace std;
void RowNumbers(int n, int max) {
if (n < max) {
cout << n << ' ';
RowNumbers(n + 1, max);
}
cout << n << ' ';
}
void PrintRhombus(int n, int space = 0) {
if (n > 1) {
PrintRhombus(n - 1, space + 2);
}
cout << string(space, ' ');
RowNumbers(1, n);
cout << "\n";
}
int main() {
int a;
cout << "Enter a number [1-9]: " << endl;
cin >> a;
if (a > 0 && a < 10) {
PrintRhombus(a, 0);
}
else
cout << "Wrong input." << endl;
}
The output is displayed here if the input is two.
1
1 2 1
This is only half of what I want. I want to make a full diamond, so I would want a "1" as the third line of this output. The RowNumbers function generates each line, and the PrintRhombus function is responsible for creating the number triangle. I only want to use recursions to create the bottom half of the triangle. So should I create another recursion function that creates the bottom half of the diamond? Or should I build upon the PrintRhombus function, and start something else when the value reaches one.
So once again my goal is to create a number diamond, so if you input 3, then the output is:
1
1 2 1
1 2 3 2 1
1 2 1
1
Here's what I would do:
First, write PrintRhombus in the form of a single loop:
void PrintRhombus(int n) {
for(int i = 1; i < 2 * n; i++){
int numbers_in_line = i < n ? i : 2 * n - i;
int space = (n - numbers_in_line) * 2;
cout << string( space, ' ' );
RowNumbers( 1, numbers_in_line );
cout << endl;
}
}
Test your loop and make sure you got it right. It's usually much easier to reason about a loop than a recursive function.
Now transform the loop into a tail-recursive function. This transformation is trivial to perform:
void PrintRhombus(int n, int i = 1){
// ^ loop variable --> extra parameter
if(i == 2 * n) return; // <- terminating condition --> return
// loop body remains unchanged
int numbers_in_line = i < n ? i : 2 * n - i;
int space = (n - numbers_in_line) * 2;
cout << string( space, ' ' );
RowNumbers( 1, numbers_in_line );
cout << endl;
// Now do recursive call with incremented loop variable
PrintRhombus(n, i+1);
}
Demo.
It is because you only iterate to the top of the rhombus, then print out the top half. I could not find a solution that used only one function, but here are two functions, one for the top and one for the bottom, that work:
void PrintRhombusTop(int n, int space = 0)
{
if (n > 1)
{
PrintRhombusTop(n - 1, space + 2);
}
cout << string(space, ' ');
RowNumbers(1, n);
cout << "\n";
}
void PrintRhombusBottom(int n, int space)
{
if (n >= 1)
{
cout << string(space, ' ');
RowNumbers(1, n);
cout << "\n";
PrintRhombusBottom(n - 1, space + 2);
}
}
Call them in main like this:
if (a > 0 && a < 10)
{
PrintRhombusTop(a, 0);
PrintRhombusBottom(a - 1, 2);
}
You need to pass (a - 1, 2) to PrintRhombusBottom so you don't print the middle row twice and so the row after the middle row is indented correctly.
to follow the same logic as RowNumber, you probably want something like that:
void PrintRhombus(int min, int max)
{
if (min < max)
{
RowNumber(1, min);
PrintRhombus(min+1, max);
RowNumber(1, min);
}
else
RowNumber(1, max);
}
Just add the necessary spaces
Another one for fun:
#include <iostream>
#include <string>
void row(int n, int m) {
std::cout << n << " ";
if (n < m) {
row(n + 1, m);
std::cout << n << " "; } }
void line(int n, int r, int m) {
std::cout << std::string(2 * (m - n), ' ');
row(1, r);
std::cout << "\n"; }
void diamond(int n, int r, int m) {
line(n, r, m);
if (r < m) {
diamond(n + 1, r + 1, m);
line(n, r, m); } }
int main(int, char* []) {
std::cout << "Number? ";
int n = 0;
std::cin >> n;
diamond(1, 1, n);
return 0; }
void CensusData::mergeSort(int type) {
if(type == 0)
MERGE_SORT(type, 0, data.size());
}
void CensusData::MERGE_SORT(int type, int p, int r){
//int q;
//cout << "data size " << data.size() << endl;
std::cout << "MERGE_SORT START ///("<< p << ", " << r << ")" <<std::endl;
if(p < r)
{
int q = (p + r)/2;
MERGE_SORT(type, p, q);
MERGE_SORT(type, q + 1, r);
MERGE(type, p, q ,r);
}
}
void CensusData::MERGE(int type, int p, int q, int r){
if(type == 0)
{
std::cout << "MERGING" << std::endl;
//int n1;
//int n2;
int n1 = q - p + 1;
int n2 = r - q;
int L[n1 + 1];
int R[n2 + 1];
for(int i = 1; i < n1; i++)
{
cout << "filling Left Array" << endl;
L[i] = data[p + i - 1]->population;
}
for(int j = 1; j < n2; j++)
{
cout << "filling Right Array" << endl;
R[j] = data[q + j]->population;
}
int i = 1;
int j = 1;
for(int k = p; p < r; p++)
{
cout << "for loop: " << endl;
if(L[i] <= R[j])
{
cout << "TRUE" << endl;
data[k]->population = L[j];
i = i + 1;
}
/*else if(data[k]->population == R[j])
{
cout << "FALSE" << endl;
j = j + 1;
}*/
else
{
data[k]->population = R[j];
j = j + 1;
}
}
}
}
do not worry about type, it wont effect this program at all. basically i am trying to make a merge sort that will take a vector containing an integer, the vector looks like this:
class Record { // declaration of a Record
public:
std::string* city;
std::string* state;
int population;
Record(std::string&, std::string&, int);
~Record();
};
std::vector<Record*> data;
basically i have been trying to get it to actually sort, but it doesn't seem to work at all, i have even seen garbage in the program.
example input:
237 812826 68642
output:
4484540 812826 68642
Note: all of the rest of the program works fine (tested it with an insertion sort) only this part is not working.
Take a look at lecture 15 of the excellent Stanford Universities course Programming Abstractions. It covers all kinds of sorts including merge:
http://see.stanford.edu/see/lecturelist.aspx?coll=11f4f422-5670-4b4c-889c-008262e09e4e
You can even get the source code from SourceForge:
http://sourceforge.net/projects/progabstrlib/files/
I am trying to write a code for merge sort. I am not getting the correct output. I am following this pseudocode link Following is my code. I pass my unsorted array into merge_sort function and call merge function recursively to sort and combine the sub arrays.I know there are more simpler and efficient ways to write code for merge sort but I want to try on my own otherwise I won't learn. Thanks in advance.
int* merge_sort(int* a,int size)
{
//cout<<size;
//cout<<"hi";
if(size == 1)
{
//cout<<"less";
//cout<<a[0];
return a;
}
int* left;
int* right;
int middle = ceil(size/2);
left = new int(middle);
right = new int(middle);
for(int i=0;i<middle;i++)
{
left[i]=a[i];
//cout<<left[i];
}
cout<<"\t";
for(int j=middle;j<size;j++)
{
right[j]=a[j];
//cout<<right[j];
}
cout<<"\t";
left = merge_sort(left,middle);
//if(size==2)
//cout<<left[0];
right = merge_sort(right,middle);
//if(size==2)
//cout<<right[0];
return merge(left,right,middle);
}
int* merge(int* l,int* r,int m)
{
int* result;
result = new int(2*m); //to store the output
int lsize=m; // to keep track of left sub list
int rsize=m; // to keep track of right sub list
int counter = 0; // will use to index result
//cout<<m;
while(lsize>0 || rsize>0)
{
if(lsize>0 && rsize>0)
{
if(l[0]<=r[0])
{
result[counter]=l[0];
counter++; //to store next value in result
lsize--;
l=&l[1]; //decrementing the size of left array
}
else
{
result[counter]=r[0];
counter++;
rsize--;
r=&r[1]; //dec. size of right array
}
}
else if(lsize>0)
{
result[counter]=l[0];
counter++;
lsize--;
l=&l[1];
}
else if(rsize>0)
{
result[counter]=l[0];
counter++;
lsize--;
l=&l[1];
}
}
return result;
}
Your code:
int *left = new int(middle);
allocates a single integer initialized to middle. You need:
int *left = new int [middle];
which allocates an array of middle integers. Rinse and repeat for int *right. Actually, you need to use:
int *right = new int [size - middle];
This gets the correct size for the right array. You then have to modify the recursive call to merge_sort() for the right sub-array:
merge_sort(right, size - middle);
Finally, you have to rewrite merge() to take the size of the left array and the size of the right array independently, because they may be of different sizes. For example, if you sort 10 elements,
you then end up with a call to merge two arrays of 5 (which is fine), but at the next level you need to merge an array of 2 and an array of 3 elements (and you're hosed).
The allocation of result also has the () vs [] allocation problem. And there are some other as yet unresolved problems. But these are important steps in the right direction.
As mentioned in a comment to the question, you have a monumental memory leakage problem, too. What's more, it is not trivial to fix because merge_sort() does an early exit without allocating new memory, so it isn't as simple as 'delete the memory returned by merge_sort()'.
Copy and paste is wonderful until you forget to edit the pasted copy correctly:
else if (lsize > 0)
{
result[counter] = l[0];
counter++;
lsize--;
l = &l[1];
}
else if (rsize > 0)
{
result[counter] = l[0];
counter++;
lsize--;
l = &l[1];
}
Methinks you should be using r and rsize in the second of these blocks.
This still isn't the whole story...
And the residual problem (apart from memory management, which is still 100% leaky and problematic) is:
for(int j=middle;j<size;j++)
{
right[j]=a[j];
//cout<<right[j];
}
You're copying into parts of right that you've not allocated. You need something more like:
for(int j = 0; j < size - middle; j++)
{
right[j] = a[j + middle];
//cout<<right[j];
}
This code works as long as you always sort at least two items at the top level (you crash freeing unallocated space if you sort 1 item — that's part of the memory management problem).
#include <iostream>
using namespace std;
namespace {
int *merge(int *l, int m, int *r, int n);
void dump_array(int *a, int size)
{
int i;
cout << size << ": ";
for (i = 0; i < size; i++)
{
cout << ' ' << a[i];
if (i % 10 == 9)
cout << '\n';
}
if (i % 10 != 0)
cout << '\n';
}
};
int *merge_sort(int *a, int size)
{
cout << "-->> merge_sort:\n";
dump_array(a, size);
if (size <= 1)
{
cout << "<<-- merge_sort: early return\n";
return a;
}
int middle = size/2;
int *left = new int[middle];
int *right = new int[size - middle];
cout << middle << ": ";
for (int i = 0; i < middle; i++)
{
left[i] = a[i];
cout << ' ' << left[i];
}
cout << "\n";
cout << (size - middle) << ": ";
for (int j = 0; j < size - middle; j++)
{
right[j] = a[j + middle];
cout << ' ' << right[j];
}
cout << "\n";
cout << "MSL:\n";
int *nleft = merge_sort(left, middle);
cout << "NL: ";
dump_array(nleft, middle);
cout << "OL: ";
dump_array(left, middle);
cout << "OR: ";
dump_array(right, size - middle);
cout << "MSR:\n";
int *nright = merge_sort(right, size - middle);
cout << "NR: ";
dump_array(nright, size - middle);
cout << "NL: ";
dump_array(nleft, middle);
cout << "OL: ";
dump_array(left, middle);
cout << "OR: ";
dump_array(right, size - middle);
int *result = merge(nleft, middle, nright, size - middle);
cout << "<<-- merge_sort:\n";
dump_array(result, size);
return result;
}
namespace {
int *merge(int *l, int m, int *r, int n)
{
int *result = new int[m + n];
int lsize = m;
int rsize = n;
int counter = 0;
cout << "-->> merge: (" << m << "," << n << ")\n";
dump_array(l, m);
dump_array(r, n);
while (lsize > 0 || rsize > 0)
{
if (lsize > 0 && rsize > 0)
{
if (l[0] <= r[0])
{
result[counter] = l[0];
cout << "C: " << counter << "; L = " << l[0] << "; LS = " << lsize << '\n';
counter++;
lsize--;
l++;
}
else
{
result[counter] = r[0];
cout << "C: " << counter << "; R = " << r[0] << "; RS = " << rsize << '\n';
counter++;
rsize--;
r++;
}
}
else if (lsize > 0)
{
result[counter] = l[0];
cout << "C: " << counter << "; L = " << l[0] << "; LS = " << lsize << '\n';
counter++;
lsize--;
l++;
}
else if (rsize > 0)
{
result[counter] = r[0];
cout << "C: " << counter << "; R = " << r[0] << "; RS = " << rsize << '\n';
counter++;
rsize--;
r++;
}
}
cout << "<<-- merge:\n";
dump_array(result, m+n);
return result;
}
};
int main()
{
for (int i = 2; i <= 10; i++)
{
int array1[] = { 9, 3, 5, 7, 1, 8, 0, 6, 2, 4 };
cout << "\nMerge array of size " << i << "\n\n";
int *result = merge_sort(array1, i);
delete[] result;
}
return 0;
}
This is the debug-laden code. It's the level to which I went to get the result. I could perhaps have used a debugger. Were I on a machine where valgrind works, it might have helped too (but it does not work on Mac OS X 10.8.x, sadly).
There are still many, many ways to improve the code — including the memory management. You'd probably find it easiest to pass the input array to merge() for use as the result array (avoiding the memory allocation in that code). This would reduce the memory management burden.
When you remove the debug code, you'll need to call the dump_array() function in the main() program to get the before and after sorting array images.
Code converted to template functions and leak-free
I've simplified the code a fair bit, especially in the merge() function. Also, more as a matter of curiosity than anything else, converted it to a set of template functions, and then used them with 4 different array types (int, double, std::string, char). The amount of debugging has been dramatically reduced, and the main debugging is conditional on being compiled with -DTRACE_ENABLED now.
The code is now leak-free; valgrind on a Linux box (virtual machine) gives it a clean bill of health when there are no exceptions. It is not guaranteed exception-safe, though. In fact, given the naked uses of new and delete, it is pretty much guaranteed not to be exception-safe. I've left the namespace control in place, but I'm far from convinced it is really correct — indeed, I'd lay odds on it not being good. (I'm also curious if anyone has any views on how to layout code within a namespace { … }; block; it seems odd not indenting everything inside a set of braces, but …)
#include <iostream>
using namespace std;
namespace {
#if !defined(TRACE_ENABLED)
#define TRACE_ENABLED 0
#endif
enum { ENABLE_TRACE = TRACE_ENABLED };
template <typename T>
void merge(T *l, int m, T *r, int n, T *result);
template <typename T>
void dump_array(const char *tag, T *a, int size)
{
int i;
cout << tag << ": (" << size << ") ";
for (i = 0; i < size; i++)
{
cout << " " << a[i];
if (i % 10 == 9)
cout << '\n';
}
if (i % 10 != 0)
cout << '\n';
}
};
template <typename T>
void merge_sort(T *a, int size)
{
if (size <= 1)
return;
if (ENABLE_TRACE)
dump_array("-->> merge_sort", a, size);
int middle = size/2;
T *left = new T[middle];
T *right = new T[size - middle];
for (int i = 0; i < middle; i++)
left[i] = a[i];
for (int j = 0; j < size - middle; j++)
right[j] = a[j + middle];
merge_sort(left, middle);
merge_sort(right, size - middle);
merge(left, middle, right, size - middle, a);
delete [] left;
delete [] right;
if (ENABLE_TRACE)
dump_array("<<-- merge_sort", a, size);
}
namespace {
template <typename T>
void merge(T *l, int m, T *r, int n, T *result)
{
T *l_end = l + m;
T *r_end = r + n;
T *out = result;
if (ENABLE_TRACE)
{
cout << "-->> merge: (" << m << "," << n << ")\n";
dump_array("L", l, m);
dump_array("R", r, n);
}
while (l < l_end && r < r_end)
{
if (*l <= *r)
*out++ = *l++;
else
*out++ = *r++;
}
while (l < l_end)
*out++ = *l++;
while (r < r_end)
*out++ = *r++;
if (ENABLE_TRACE)
dump_array("<<-- merge", result, m+n);
}
};
#include <string>
int main()
{
for (size_t i = 1; i <= 10; i++)
{
int array1[] = { 9, 3, 5, 7, 1, 8, 0, 6, 2, 4 };
if (i <= sizeof(array1)/sizeof(array1[0]))
{
cout << "\nMerge array of type int of size " << i << "\n\n";
dump_array("Original", array1, i);
merge_sort(array1, i);
dump_array("PostSort", array1, i);
}
}
for (size_t i = 1; i <= 10; i++)
{
double array2[] = { 9.9, 3.1, 5.2, 7.3, 1.4, 8.5, 0.6, 6.7, 2.8, 4.9 };
if (i <= sizeof(array2)/sizeof(array2[0]))
{
cout << "\nMerge array of type double of size " << i << "\n\n";
dump_array("Original", array2, i);
merge_sort(array2, i);
dump_array("PostSort", array2, i);
}
}
for (size_t i = 1; i <= 10; i++)
{
std::string array3[] = { "nine", "three", "five", "seven", "one", "eight", "zero", "six", "two", "four" };
if (i <= sizeof(array3)/sizeof(array3[0]))
{
cout << "\nMerge array type std::string of size " << i << "\n\n";
dump_array("Original", array3, i);
merge_sort(array3, i);
dump_array("PostSort", array3, i);
}
}
for (size_t i = 1; i <= 10; i++)
{
char array4[] = "jdfhbiagce";
if (i <= sizeof(array4)/sizeof(array4[0]))
{
cout << "\nMerge array type char of size " << i << "\n\n";
dump_array("Original", array4, i);
merge_sort(array4, i);
dump_array("PostSort", array4, i);
}
}
return 0;
}