In: Computer Science
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;
}
// 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;
}