//	HOMEWORK 220 #1
//	Insert an element into an ordered array.
//	Shift elements forward to make room for the new element.
//	Driver program
//	Print function
//	Insert function

# include
using namespace std;

void insert(int [ ], int&, int);
void print(int [ ], int);

int main( )
{
	int n = 10;
	int scores[20] = {0,10,20,30,40,50,60,70,80,90};
	int x;

	print(scores,n);
	cout << "Enter element you wish to insert." << endl;
	cin >> x;
	insert(scores,n,x);
	print(scores,n);
	return 0;
}

//	Start at the high end of the array and search backward for
//	the correct location for x.  As we search, move the elements 
//	that are larger than x one position to the right to make room 
//	for x.

void insert(int scores[ ], int &n, int x)
{
	int i;
	for (i=n; i > 0 && x < scores[i-1]; i--)
		scores[i] = scores[i-1];
	scores[i] = x;
	n++;
}

void print(int scores[ ], int n)
{
	for (int i=0; i

    Source: geocities.com/vuumanj/DataStructures

               ( geocities.com/vuumanj)