Question

In: Computer Science

Looking for some more simple pseudocode (examples in bold italicized font below) for this chunk of...

Looking for some more simple pseudocode (examples in bold italicized font below) for this chunk of program? I have added some, but my professor prefers more than this, thank you and THUMBS UP always left for good answers!

---------------------------------------------------------------------------------------------------------------------------

       VectorStack<Integer> lowerValues = new VectorStack<Integer>();

       VectorStack<Integer> upperValues = new VectorStack<Integer>();

       for (int i = 0; i < data.length; i++)

       {

           lowerValues.push(data[i]);

       }
// While the lower values are not empty
       while (!lowerValues.isEmpty()) {

           temp = lowerValues.pop();

           while ((!upperValues.isEmpty() && temp < upperValues.peek()))

           {

               lowerValues.push(upperValues.pop());

// Push the pop of upper value

           }

           upperValues.push(temp);

       }

       while (!upperValues.isEmpty()) {

           for (int b = 0; b < data.length; b++) {

               result[b] = upperValues.pop();

               System.out.println(result[b]);

           }

       }

       return result;

   }

Solutions

Expert Solution

// Create a stack of integers to store the lower values

VectorStack<Integer> lowerValues = new VectorStack<Integer>();

// Create a stack of integers to store the upper values

VectorStack<Integer> upperValues = new VectorStack<Integer>();

// Iterate through the data array and push each element to the stack lowerValues stack   

for (int i = 0; i < data.length; i++)

{

           lowerValues.push(data[i]);

}
// Now iterate through the lowerValues array until it is empty
       while (!lowerValues.isEmpty()) {

// pop an element from lowerValues and store it in temp

           temp = lowerValues.pop();

// Now iterate through the upperValues stack until it is empty and the top element is greater then temp

           while ((!upperValues.isEmpty() && temp < upperValues.peek()))

           {

// pop an element from upperValues and push it to lowerValues

               lowerValues.push(upperValues.pop());

           }

// Now, push temp to upperValues stack

           upperValues.push(temp);

       }

// finally iterate through the upperValues stack until it is empty

       while (!upperValues.isEmpty()) {

// iterate through the data array

           for (int b = 0; b < data.length; b++) {

// pop the element from upperValue and store it in result[b]

               result[b] = upperValues.pop();

// print the value of result[b]

               System.out.println(result[b]);

           }

       }

// return result array

       return result;

   }


Related Solutions

Can I get some simple pseudocode (simple descriptions as exampled in top italicized line) added to...
Can I get some simple pseudocode (simple descriptions as exampled in top italicized line) added to this small section of Java code? Thumbs up always left for answers! ------------------------------------------------------------------------------------------------------- // Check to see if two bags are equals.    public boolean equals(LinkedBag<T> aBag) {        boolean result = false; // result of comparison of bags        if (this.numberOfEntries == aBag.numberOfEntries) {            if (numberOfEntries == 0) {                return true;           ...
Other than looking only at the EU and Turkey, what are some examples of complex interdependence...
Other than looking only at the EU and Turkey, what are some examples of complex interdependence at work? Why is complex interdependence so important in understanding today's world?
Try to make it as simple as you can. Please provide the answers with some examples...
Try to make it as simple as you can. Please provide the answers with some examples as fast as you can. 11-Which of the following do all domains in the same forest have in common? (Choose all that apply.) a) The same domain name    b) The same schema c) The same user accounts    d) The same global catalog   12-Which of the following is a valid reason for using multiple forests? a) Centralized management     b) Need for different schemas c) Easy...
Other than looking only at the Indo-Pacific region, what are some examples of economic integration and...
Other than looking only at the Indo-Pacific region, what are some examples of economic integration and cooperation at work?
Why do some firms appear to embrace the minimum wage legislation? Looking at examples for minimum...
Why do some firms appear to embrace the minimum wage legislation? Looking at examples for minimum wage around the world, what are the likely forces driving behind this legislation? Is the minimum wage legislation tied to income per capita or income inequality? The empirical evidence of the impact of minimum wage legislation on employment and local economies is mixed. In fact, studies have found, negative, positive and zero impact. Can you explain this discrepancy? How do attitudes towards minimum wage...
Construct some simple examples to illustrate your answers to the following: a. If interest rates fall,...
Construct some simple examples to illustrate your answers to the following: a. If interest rates fall, do bond prices rise or fall? b. If the bond yield to maturity is less than the coupon, is the price of the bond greater or less than the par value? c. If the price of a bond is below the par value, is the yield to maturity greater or less than the coupon? d. Do low-coupon bonds sell at higher or lower prices...
Part A What are some examples that you have experienced in relation to one or more...
Part A What are some examples that you have experienced in relation to one or more of the pricing models/tactics? Part B Why might penetration pricing potentially negatively impact brand image and product positioning in the long run? Given this risk, why would a marketing manager use penetration pricing? Identify a brand (other than the examples in the chapter) that you believe is engaged in penetration pricing.
Some results of simple physics experiments conducted on planet Earth are not intuitive. Examples include determining...
Some results of simple physics experiments conducted on planet Earth are not intuitive. Examples include determining the acceleration of a ball tossed upwards at the point when its instantaneous vertical velocity is zero, and the time it takes two balls to hit the ground when they are tossed off the same horizontal surface at different initial horizontal velocities. Discuss each of these results and provide the reasoning that explains the apparently non-intuitive outcomes.
Consider the many examples contained in the lecture. Do you find some to be more important...
Consider the many examples contained in the lecture. Do you find some to be more important than others? Identify one that you believe to have an enduring legacy on human history. Explain why you believe that it may still have an impact on us today.
In 175 words or more give some common examples of accrued revenue and accrued expenses that...
In 175 words or more give some common examples of accrued revenue and accrued expenses that may occur in a business. Discuss why they arise, how they are recorded, and why it is necessary to record them.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT