Question

In: Computer Science

Say I have and Array so MyArray starts off as S A Q W A R...

Say I have and Array so MyArray starts off as S A Q W A R .... I want to sort the Array alphabetically using ascii codes to sort. However in Ascii code capital letters come first and then lower case letters are sorted after. My goal is to not only sort the array, but also make lowercase sorted in its proper place. I am using visual basics and I cant use a built in sorter that does it the easy way, I have to sort it somehow in visual basics. please help me learn how todo this! Will rate very highly, thanks so much!

Solutions

Expert Solution

Hi According to your requirement i have written the code. It will sort the array content exactly as per your query.

Code:

#define CLASS_SIZE 10
#include <stdio.h>

void sortingCharArray(const char a[], char * b[]);

int main(void){
int i;

// initialize array
char * sortingOperationArray[CLASS_SIZE];
char myArray[CLASS_SIZE] = {'a','r','p','b','r','c','x','e','w','j'};
// sort array
sortingCharArray(myArray,sortingOperationArray);

// print sorted array
for (i=0;i<CLASS_SIZE;i++){
printf("%c\n", *sortingOperationArray[i]);
}

return 0;
}

void sortingCharArray(const char a[], char * b[]){
char * temp;
int i,j;

// initialize b array to hold pointers to each element in a
for (i=0;i<CLASS_SIZE;i++){
b[i] = (char *)(a) + i;
}

// in-place sort the b array
for(i=0;i<CLASS_SIZE;i++){
for(j=i+1;j<CLASS_SIZE-1;j++){
if(*b[j-1]>*b[j]){
temp = b[j];
b[j] = b[j-1];
b[j-1] = temp;
}
}   
}
}


Related Solutions

Prove p → (q ∨ r), q → s, r → s ⊢ p → s
Prove p → (q ∨ r), q → s, r → s ⊢ p → s
Assume that product codes are formed from the letters X, S, W, R, and Q, and...
Assume that product codes are formed from the letters X, S, W, R, and Q, and consist of 6 not necessarily distinct letters arranged one after the other. For example, XXQSWQ is a product code. (1) How many different product codes are there? (2) How many different product codes do not contain S? (3) How many different product codes contain exactly one Q?
Create a class and name it MyArray. This class must have an internal array of integers...
Create a class and name it MyArray. This class must have an internal array of integers and the consumer should specify the maximum capacity when instantiating. MyArray class must provide following functions: 1- insert: This method receives and integer and inserts into the array. For simplicity you can assume the array is large enough and never overflows. 2- display: This method displays all integers stored in the array in the same order as they are inserted (first in first out)....
How would I prove this ? R > A / R > ( A v W...
How would I prove this ? R > A / R > ( A v W ) I was thinking that this would work but I am not sure. 2. R > (A v W) 1, MP
Suppose S = {p, q, r, s, t, u} and A = {p, q, s, t}...
Suppose S = {p, q, r, s, t, u} and A = {p, q, s, t} and B = {r, s, t, u} are events. x p q r s t u p(x) 0.15 0.25 0.2 0.15 0.1 (a) Determine what must be p(s). (b) Find p(A), p(B) and p(A∩B). (c) Determine whether A and B are independent. Explain. (d) Arer A and B mutually exclusive? Explain. (e) Does this table represent a probability istribution of any random variable? Explain.
So let's say I got 60% in test. then we have to divide that into 2...
So let's say I got 60% in test. then we have to divide that into 2 so now I got 30% and then we have to add 50% to it. So my final test marks is 80%. write a function in C++ that takes a map<string, int> which represents a students name to their test marks and returns a map<string, double> which represents the upgraded marks. Please write this function without using any for or while loops. Example: Input: {{"Ved",...
So let's say I got 60% in test. then we have to divide that into 2...
So let's say I got 60% in test. then we have to divide that into 2 so now I got 30% and then we have to add 50% to it. So my final test marks is 80%. write a function in C++ that takes a map<string, int> which represents a students name to their test marks and returns a map<string, double> which represents the upgraded marks. Please write this function named "upgraded_marks" without using any for or while loops. Example:...
Quick question, so say I have a mean of 511, a standard deviation of 124 and...
Quick question, so say I have a mean of 511, a standard deviation of 124 and then I have less then 650. I do 650-511=139. I take the 139 and divide that by 124 and get 1.12. now with the z table that would become 0.8686, how do I do the z table because i am very confused on how to convert the answer to the z table.
Assume that, in the short-run, K = 16, w = 3, r = 8, and Q...
Assume that, in the short-run, K = 16, w = 3, r = 8, and Q = 3 4KL. Graph the Total Cost, Fixed Cost, Variable Cost, Average Total Cost, Average Variable Cost, Average Fixed Cost, and Marginal Cost curves. Label your graph carefully.
2. We say the rv X has the "W" distribution with parameter q > 0 (written...
2. We say the rv X has the "W" distribution with parameter q > 0 (written X ~ W(q) ) if X has pdf f(x)= 2x/q^2, for 0 < x < q, and f(x) = 0, elsewhere. Consider the parameterized "W" family {W(q) : q > 0 }. a) Let Yn be the maximum of the random sample of size n from W(q). Show that Yn is a consistent estimator of q. Note here that is the q is the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT