All pastes #90488 Raw Edit

Untitled

public cpp v1 · immutable
#90488 ·published 2006-07-17 18:48 UTC
rendered paste body
#include <iostream>using namespace std;//prototype declerationsvoid printarray();void generatearray(int array[], int nSize);void printarray(int array[], int nSize);void bubblesort(int array[], int nSize);int main(){   int nSize = 0;   cout << "Enter the size of the array: ";   cin >> nSize;                 //size of array   cout << endl;   int *array = new int[nSize];  //create pointer to dynamic array   generatearray(array,nSize);   printarray(array,nSize);   bubblesort(array,nSize);   printarray(array,nSize);   delete[] array; //free memory   system("Pause");}void generatearray(int array[], int nSize){   for (int i = 0; i < nSize; i++)   {      array[i] = rand();   }}void printarray(int array[], int nSize){   for (int i = 0; i < nSize; i++)   {      cout.width(3);      cout << i+1 << ": " << array[i] << endl;   }   cout << endl;}void bubblesort(int array[], int nSize){   bool bSorted = 0;  //set sorted to false   int nTemp1;   do   {     bSorted = 1;  //set sorted to true     for (int i = 0; i < nSize; i++)        if (array[i] > array[i+1])        {           nTemp1 = array[i];           array[i] = array[i+1];       //swap values           array[i+1] = nTemp1;           bSorted = 0;             //not sorted if this path taken        }   } while (bSorted == 0);}