I was humming along, and decided to try out data sorting. So, I did a few pieces of research, and came up with a really cool looking algorithm: Quicksort. I did what I should have, and started to program. Now, here is where I sound like an idiot:
Why is this not working?

The code is attached below. I wrote it up in Microsoft Visual Basic C++ 2010 Express. Every time I run it it gets the following error, and I cannot for the life of me find out why. Any help (at all) would be greatly appreciated, as I am new to C++ (I did Java mostly before this).

Thanks in advance,
EneilShade

Attachments
// QuickSort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>

using namespace std;

int* quicksort(int *Array);

int _tmain(int argc, _TCHAR* argv[])
{
	int  Start[500]  = {0};
	bool Random[500] = {0};
	int  *Final      = new int(500);
	int  Counted     = 0;
	int  Rand;

	srand(time(NULL));

	for (int i = 0; i < 500; i ++)
	{
		Start[i] = i;
		Final[i] = 0;
	}

	while (Counted++ < 500)
	{
		Rand = rand() % 500;

		while (Random[Rand] == true)
		{
			if (++Rand > 499)
			{
				Rand = 0;
			}
		}

		Random[Rand] = true;

		Final[Counted] = Start[Rand];
	}

	Final = quicksort(Final);

	for (int i = 0; i < 500; i ++)
	{
		cout << Final[i] << "\n";
	}

	system("PAUSE");

	return 0;
}


int* quicksort(int *Array)
{
	int Size = sizeof Array / sizeof Array[0];

	if (Size > 1)
	{
		int *Upper = new int[Size];
		int Upct = 0;
		int *Lower = new int[Size];
		int Lwct = 0;

		int PivotLocation = rand() % Size;

		int Pivot = Array[PivotLocation];

		for (int i = 0; i < Size; i ++)
		{
			int Current = Array[i];

			if (Current >= Pivot)
			{
				Upper[Upct++] = Current;
			}
			else if (Current < Pivot)
			{
				Lower[Lwct++] = Current;
			}
		}

		int *RUpper = new int[Upct];
		int *RLower = new int[Lwct];

		for (int i = 0; i < Upct; i ++)
		{
			RUpper[i] = Upper[i];
		}

		for (int i = 0; i < Lwct; i ++)
		{
			RLower[i] = Lower[i];
		}

		RUpper = quicksort(RUpper);
		RLower = quicksort(RLower);

		int *Final = new int[Size];

		for (int i = 0; i < Lwct; i ++)
		{
			Final[i] = RLower[i];
		}

		for (int i = Lwct; i < Upct; i ++)
		{
			Final[i] = RUpper[i];
		}

		delete[] Upper;
		delete[] RUpper;
		delete[] Lower;
		delete[] RLower;

		return Final;
	}
	else
	{
		return Array;
	}
}
// stdafx.cpp : source file that includes just the standard includes
// QuickSort.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

Your statement

int Size = sizeof Array / sizeof Array[0];

will not work if Array is a formal parameter, because in that case, Array is simply a pointer and sizeof Array is the size of a pointer. If you want to use an array parameter to represent an array, you have to pass the size separately.

Wow... I had looked at the Wikipedia page wrong... I hate learning something wrong from the beginning. My problem was with a fundamental understanding of quicksort, nothing else.

Your statement

int Size = sizeof Array / sizeof Array[0];

will not work if Array is a formal parameter, because in that case, Array is simply a pointer and sizeof Array is the size of a pointer. If you want to use an array parameter to represent an array, you have to pass the size separately.

Thanks, but I had solved this just before you posted. But that comment will help me in the future!

This question has already been answered. Start a new discussion instead.