Question

public void sort(int NumElements) 
{
     int[] numbers = new int[node - 1];
     int temphead = head;

     for(int i = NumElements; i > 1; i--)       // for statement grabbing values to sort.
     {
         if(stack.getfloor(temphead) != 0)
         {
             numbers[i] = (stack.getfloor(temphead)); 
         }
         temphead = stack.getBLink(temphead);
     }

    int tempVar;

    for (int i = 0; i < numbers.length; i++)     // bubble sort. 
    {
             for(int j = 1; j < numbers.length - 1; j++)
             {
                     if(numbers[i] > numbers[j + 1])
                     {
                     tempVar = numbers [j + 1];
                     numbers [j + 1] = numbers [i];
                     numbers [i] = tempVar;
                     }
             }
    }
    int temphead2 = head;

    for(int i = NumElements; i > 1; i--)
    {
        remove();                           // removes all vales
    }
    for(int i = NumElements; i > 1; i--)
    {
        insert(1,numbers[i]);               // adds all vales

    }
}

Fulling working: Working with "Double link Queue" -> "handle by stack" -> "Basic attribute tree" The Above has been fixed And is part of the Double link queue Sort method. The sort method as shown calls stack. The stack has basic methods to hold and give data when called. The stack is a link stack. After such infomation is requested from its methods the following functions puts the Floor levels it got back randomly from stack, Aka the queue path. after it used its bubble sort to order it in the following the old data in the stack is removed and free up for use. the sort the Puts "Numbers[i] the sorted array back into the stack. it does this by using basic sort methods in the double link and basic removes. If you wish to see the full code, i will gladly send it.

Was it helpful?

Solution

*assuming your variable numbers is the same as numbers2 and you have a typo

Array size must be declared to initialize an array in java.

int[] numbers = new int[size-1];
for(int i = size ; i > 1; i--)
{
    int temphead = head;
    numbers[i] = stack.getpeople(temphead);
    temphead = stack.getBLink(temphead);
}

Or you can use a List to contain your elements

ArrayList<Integer> numbers = new ArrayList<Integer();
for(int i = size ; i > 1; i--)
{
    int temphead = head;
    numbers.add(stack.getpeople(temphead));
    temphead = stack.getBLink(temphead);
}

if you use a list you will need to redeclare all your references to numbers. numbers[i] would be numbers.get(i) and numbers.length would be numbers.size()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top