Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert the shuffle-left pseudo code to C code. 1. Set the value of legit to upp

ID: 3744036 • Letter: C

Question

Convert the shuffle-left pseudo code to C code.

1. Set the value of legit to upper 2. Set the value of left to 1 3. Set the value of right to 2 4. While left is less than or equal to legit do steps 5 through 12 5. If the item at position left is not 0 then do steps 6 and 7 6. Increment left by 1 7. Increment right by 1 Else (the item at position left is 0) do steps 8 through 12 8. Decrement legit by 1 9.While right is less than or equal to upper do steps 10 and 11 10. Copy the item at position right into position (right 1) Increment right by 1 12. Set the value of right to (left1) 13. Print the value of legit 14. Stop

Explanation / Answer

/************************************************

Here's the implementation in C

The function that is implemented is shuffle_left

and takes two arguments, (1) and integer, upper

(2) an array of elements

It implements the pseudocode and does operations

on the array and displays the value of legit in the end.

Everything that is implemented in the main function is

for testing purposes. You may choose to remove it.

Lastly do give a feedback about this.

It would help a lot.

**************************************************/

#include <stdio.h>

void shuffle_left(int arr[], int upper) {

int legit = upper, left = 1, right = 2;

while(left <= legit) {

if(arr[left] != 0) {

left++;

right++;

} else {

legit--;

while(right <= upper) {

arr[right - 1] = arr[right];

right++;

}

right = left + 1;

}

}

printf("legit: %d ", legit);

}

int main() {

int arr[] = {1, 0, 3, 4, 0, 0, 7, 8, 9, 5};

shuffle_left(arr, 9);

for(int i = 0; i < 10; i++)

printf("%d ", arr[i]);

printf(" ");

return 0;

}