B
Bailey.W87
my professor give me this assignment. Sort the R's B's and W's in an
array. for example, the user enter:
R B W W B B R W W R R W R B W
i need to swap the characters in the array and arrange it into
R R R R R W W W W W W B B B B
--------------------------------------------------------------------
i am thinking if i can set the R's = 1 W's=2 B's =3 then sort it out as
number from small to largest.
this is what i have so far.
#include <stdio.h>
#include <string.h>
#define MAX 81
void getchars(char *flag ) {
char 'R'=1;
char 'W'=2;
char 'B'=3;
printf("Please Enter Letters R's W's B's Only\n");
gets(flag);
}
int getlargest(double array[ ], int size) {
int index=0;
double big = array [ index];
int i;
for( i=1; i < size; i++) {
if (array> big;
index=1;
}
}
return index;
}
void sortFlag( char array[ ], int size) {
int end;
int large;
int lastplace= size -1 ;
double temp;
for (end=lastplace; end> 0; end --) {
large=getlargest(array, end+1);
temp=array[large];
array[index]=array[end];
array[end]=temp;
}
}
int main () {
char flag[MAX];
getchars(flag);
printf(flag);
return 0;
}
array. for example, the user enter:
R B W W B B R W W R R W R B W
i need to swap the characters in the array and arrange it into
R R R R R W W W W W W B B B B
--------------------------------------------------------------------
i am thinking if i can set the R's = 1 W's=2 B's =3 then sort it out as
number from small to largest.
this is what i have so far.
#include <stdio.h>
#include <string.h>
#define MAX 81
void getchars(char *flag ) {
char 'R'=1;
char 'W'=2;
char 'B'=3;
printf("Please Enter Letters R's W's B's Only\n");
gets(flag);
}
int getlargest(double array[ ], int size) {
int index=0;
double big = array [ index];
int i;
for( i=1; i < size; i++) {
if (array> big;
index=1;
}
}
return index;
}
void sortFlag( char array[ ], int size) {
int end;
int large;
int lastplace= size -1 ;
double temp;
for (end=lastplace; end> 0; end --) {
large=getlargest(array, end+1);
temp=array[large];
array[index]=array[end];
array[end]=temp;
}
}
int main () {
char flag[MAX];
getchars(flag);
printf(flag);
return 0;
}