Question

I need help converting this pseudocode into a c++ program. Thanks Procedure- mystery algorithm1(L=a1...an:real numbers) if...

I need help converting this pseudocode into a c++ program. Thanks

Procedure-
mystery algorithm1(L=a1...an:real numbers)
if n>1 then
m1=n/3
m2=2*(n/3)
L1=a1....am1
L2=am1+1....am2
L=mystery algorithm2(mystery algorithm1(L1),mystery algorithm1(L2))
return L


Procedure-
mystery algorithm2(L1,L2)
L= empty list
while L1 and L2 are both nonempty
remove smaller of first elements of L1 and L2 from its list; put it at the right end of L
if this removal makes one list empty then remove all elements from the other list and append them to L.
return L

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

I thoght I hava done with template

#include <iostream>

using namespace std;

double* mysteryalgorithm2(double L1[],double L2[])
{
double L[20];
int listOneSmaller,listTwoSmaller;
int i=0,j=0,k=(sizeof(L1)/sizeof(*L1))+(sizeof(L2)/sizeof(*L2));
while(i > (sizeof(L1)/sizeof(*L1) && (sizeof(L2)/sizeof(*L2))))
{
listOneSmaller=L1[0];
listTwoSmaller=L2[0];
if(listOneSmaller < L1[i+1]){
listOneSmaller=L1[i+1];
L[k] = listOneSmaller;
}
i++;

if(listTwoSmaller<L2[j++]){
listTwoSmaller=L2[j++];
L[k-1]=listTwoSmaller;

}
j++;
k--;
}

}


double* mysteryalgorithm1(double L[],int n)
{
int m1,m2;
double L1[n],L2[n];
if (n > 1)
{
m1=n/3;
m2=2*(n/3);
for(int i=0;i<m1;i++)
L1[i]=L[i];
for(int j=m1+1,l=0;j<m2;j++,l++)
L2[l]=L[j];
for(int k=0;k<n;k++)
L=mysteryalgorithm2(mysteryalgorithm1(L1,m1),mysteryalgorithm1(L2,m2));

return L;
}

}
int main()
{
double L[20],output[20],*p;
int n;
cout << "Enter number of elements in List:";
cin >> n;
cout << "Enter elements of the List:";
for(int i=0;i<n;i++)
cin >> L[i];
p=mysteryalgorithm1(L,n);
cout << "List L elements :\n";
for(int i=0;i<n;i++)
cout << *(p+1) << " " ;
return 0;
}


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
I need help converting this pseudocode into a c++ program. Thanks Procedure- mystery algorithm1(L=a1...an:real numbers) if...
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
  • Given list.h, main.cpp, i need to write list.cpp. having a lot of problems. please help. list.h:...

    Given list.h, main.cpp, i need to write list.cpp. having a lot of problems. please help. list.h: ////////////////////////////////////////////////////////////////////////// #ifndef LIST_H #define LIST_H ////////////////////////////////////////////////////////////////////////// namespace CS170 { struct node { int value; node *next; }; class list { public: // Constructor for list. Creates an empty list list(); /* Destructor for list. Empty the list and release the allocated memory */ ~list(); // Prints out the values contained in the list void print_list() const; // Returns the current size of the list...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • Help on the answers making sure what I’ve done is right and helping with the ones...

    Help on the answers making sure what I’ve done is right and helping with the ones I don’t have. Understanding Check ubital nerva 1. A surgen sutures a lacerated cubital nerve branch of the Coingres a 01s4022 c O1TYO2zz d oissozz 9. 10-PCS, the spiral ganglion is classified as part of the 2 In ICD-1 llay pontine, and superior are examples of names of 3 Cerebromedu a. Ganglia 10. h Meninges Cisterns d. Nerves ents: Resection of tumor of meninges...

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