// PROG2207.CPP
// Dumb Bubble-Sort Algorithm


#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <iomanip.h>
#include "APVECTOR.H"


typedef apvector <int> ListType;
void CreateList(ListType &List);
void DisplayList(const ListType &List);
void SortList(ListType &List);
void Swap(int &A, int &B);


void main()
{
   clrscr();
   ListType List(12);
   CreateList(List);
   DisplayList(List);
   SortList(List);
   DisplayList(List);
}


void CreateList(ListType &List)
{
   int N = List.length();
   int K;
   for (K = 0; K < N; K++)
      List[K] = random(9000) + 1000;
}


void DisplayList(const ListType &List)
{
   cout << endl << endl;
   int N = List.length();
   int K;
   for (K = 0; K < N; K++)
      cout << setw(5) << List[K];
   cout << endl;
   getch();
}


void Swap(int &A, int &B)
{
   int T;
   T = A;  A = B;  B = T;
}


void SortList(ListType &List)
{
   int P,Q;
   int N = List.length();
   for (P = 1; P <= N-1; P++)
      for (Q = 0; Q < N-P; Q++)
	 if (List[Q] > List[Q+1])
	    Swap(List[Q],List[Q+1]);
}

