Question

Convert the Convergent-Pointer Algorithm pseudo code to C code. Use exact variables and make no modifications.

Get values for n and the n data items Set the value of legit to n Set the value of left to 1 Set the value of right to n While left is less than right do 1 If the item at position left is not 0 then Increase left by 1 Otherwise Reduce legit by 1 Copy the item at position right into Reduce right by 1 End of loop If the item at position left is 0 then Reduce legit by 1 Stop

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Below is the answer to your question

#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include <math.h>
int main()
{
int n;//define n
printf("Enter n: ");//print
scanf("%d",&n);// input n
printf("Enter n data items\n");
int data[n];
int i;
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);////input data itemss
}
int legit=n,left=1,right=n;// define legit, left and right
while(left<right)// loop while left is less than right
{
if(data[left]!=0)// element at left is not 0
left=left+1;// increment left
else
{
legit--;// reduce legit by 1
data[left]=data[right];// copy right to left
right--;// reduce right by 1
}
}
if(data[left]==0)// if element at left is zero
legit--;// reduce legit by 1


return 0;
}

main.c-Code: Blocks 13.12 Eile Edit iew Search Project Build Debug Fortran wmith Tools Tools+ Plugins DoyBlocks Settings Help Start Enter n: 5 Enter n data items 15 16 19 20 Process returned e (ex) execution time 29.714s Press any key to continue 25 34 Logs &othe ㄨ Build log× ずBu d messages X CppCheck × CppCheck messages X nCsc pe >: Debugger X nDoxy테。cks >: Fortran info × aosed files list < cbThread search ming 32-gtt.exe- F:checkimain.exe F:checkimain.o Process torminated rith status ro minutof0 s0oond fa) 0 error (s), v교ening (s) (0 minut. (5), o second (s)) Chacking tor existencechecimain.axe Executing : G:\CodeBlocks/cb-console-runner.exe F:\check\main.exe. <in F:\check) Windows (CR+LF) WINDOWS-1252 Line 34, Column 1 Insert Read/Write default O Type here to search ENG 828 PM US 09/08/18 8

Kindly revert for any queries, will be waiting for your positive feedback.:)

Thanks.

Add a comment
Know the answer?
Add Answer to:
Convert the Convergent-Pointer Algorithm pseudo code to C code. Use exact variables and make no modifications....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT