Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please- When we swap two variables x and y, the value of x gets copied onto y and viceversa. In general, we utilize

In C++ Please-

When we swap two variables x and y, the value of x gets copied onto y and viceversa. In general, we utilize a third variable to temporarily store one of the values we are swapping. If we wanted to enforce an order on our array, perhaps an z-a reverse lexicographic order, we would then need to swap all of the letters into the correct positions in the array. This means the letter with the lowest ASCII value would be farthest to the left, and the letter with the highest ASCII value would be farthest to the right.

The provided code template gives you a starting point on how to go about enforcing an z-a reverse lexicographic ordering (i.e. descending order) on the following array

arr.

image text in transcribed

Your first objective is to write an if-else block that uses the algorithm for swapping so that the first element of the array is the first letter of the alphabet (lowest ASCII value character).

Your second objective is to modify the for-loop with the if-else block such that every time the for-loop with the if-else block is executed it processes progressively smaller arrays. You should nest the for-loop with the if-else block inside another for-loop and then modify the index variable is bounds to achieve this. For example, the first time it is executed it should process the entire array, the second time it should process the entire array except the first position, the third time it should process the entire array except the first two positions, etc. We only need to process smaller portions of the array each time, because we know that left most characters are slowly being sorted into the reversed lexicographic order with every pass of the algorithm, and so there is no need to resort them. The final ordering of your letters should be: z t q m g f b a

#include using namespace std; int main() { char arr[]={'b','f', 'a','z','m','g', 'a', 't'}; for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago