Alg 2: Insert \'x\' after the last element in the list stored within the array a
ID: 3664476 • Letter: A
Question
Alg 2: Insert 'x' after the last element in the list stored within the array a. Assume the following declarations: char a[100]; int aSize=32; char ch; Assume also that the first 32 elements have been initialized to some values and the remaining elements have garbage in them. In the question below the term list stored within the array a means the elements found from position 0 to position 31. The phrase last element in the list refers to the element found in 'a[31]'. The phrase element at position n, refers to the n-th element of a list, which is stored in 'a[n-1]'. If you add or delete anything from the array, make sure you adjust aSize approriately.
Explanation / Answer
char a[100];
int aSize = 32; // current size
// Methods to inser a element in array
void insert(char element) {
a[aSize] = element;
aSize = aSize + 1; // increase size
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.