Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Can you write algorithm and comment for the fllowing C++ code. The form of algorithm and comment show in the picture. void cocktailSort(int pData[], int

//Can you write algorithm and comment for the fllowing C++ code. The form of algorithm and comment show in the picture.

image text in transcribed

void cocktailSort(int pData[], int Count)

{

int iTemp;

int ant = 0;

int ans = 0;

int left = 1;

int right = Count - 1;

int k=0;

if(Count==5&&pData[0]==1&&pData[4]==0)

k = 9;

int t;

do

{

int i;

for (i = right; i >= left; i--)

{

ant++;

if (pData[i]

{

iTemp = pData[i];

pData[i] = pData[i - 1];

pData[i - 1] = iTemp;

t = i;

ans++;

}

}

left = t + 1;

//

for (i = left; i

{

ant++;

if (pData[i]

{

iTemp = pData[i];

pData[i] = pData[i - 1];

pData[i - 1] = iTemp;

t = i;

ans++;

}

}

right = t - 1;

} while (left

cout

for (int i = 0; i

cout

cout

if(k!=0)

cout

else if(Count==5&&pData[4]!=0&&pData[4]!=4)

cout

else if(Count==10)

cout

else if(Count==27)

cout

else if(Count==5&&pData[4]==4&&pData[0]==1)

cout

else

cout

cout

}

7 using namespace std; ALgorithe: that checks what range a given NPG folls into . 1. Take the mpg value passed to the function. 11 12 13 14 15 16 Comments (10 points) 2 Check f tt is greater than se If yes, then print "Nice Job . If not, then check f t ts greater than 25 Alorithm If yes, then print "Not great, but oay 4. If not, then print "So bad, so very, very bad (10 points) Input parometers: iles per gollon (Float type 18Output:dfferent string bosed on three cotegortes of G:50, 25-49, and Less than 25 Returns: nothing 21 23 void checkPG(Float mpg) 50) check f the Input volue ts greater than 5e 25 26 27 28 29 30 31 32 cout ee "Nice job e endl; 7 output message lse if(ng25) 7/ff not, check f is greater than 25 cout

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions