1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <cstring>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std ;
//This program orders numbers passing references
//function to order.The inputs are the adresses where those values are stored.
//Directly changing it's value.
int order(const char C[], const char B[]){
int i = strcmp(C,B);
cout << "C is: "<< C << " B is: " << B <<" i is: " << i <<endl;
if(i<0){
const char *d;
//change the order if the IF is fullfilled
d=C;
cout <<"D is: " << d << endl;
C=B;
B=d;
cout << "C is: "<< C << " B is: " << B << " d is" << d << endl;
}
return 0;
}
//function to sort the array. Pointer A pointing to where x variable is stored
const char * sort(const char * A[]){
int i,j,d;
for (i=0; i<10; i++) {
for (j=0; j<10-i; j++) {
//condition for not taking into account A[10] which is undefined
if(j==9){
continue;
}
//call order sending two integers
order(A[j+1],A[j]);
cout <<"After order, A[" << j <<"] is: " << A[j] << endl;
}
}
return A[9];
}
//Main function
int main(){
int i;
const char* x[] = { "blue", "and", "mint", "sand", "ten", "hold", "danke", "figure", "apple", "gain" };
//call the sort function
x[10]=sort(x);
//print the array to see it is in order
for(i=0;i<10;i++){
cout << x[i]<<endl;
}
//delete [] x;
return 0;
}
|