Thread: apqueue

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    85

    apqueue

    i need help with a program, that implements the radix sort method.

    apvector<int> QueuesToArray(apvector<apqueue<int> >&QA, int numVals)
    //step two of radix sort
    {
    apvector<int>Array(numVals);
    int t,count=0;
    for(int i=0; i<QA.length(); i++){
    for(int j=0; j<QA[i].length();j++){
    Array[count]=QA[i].front();
    QA[i].dequeue(Array[count]);
    count++;
    }
    }
    return Array;
    }

    i am trying to set the array = the first element in the queue, then deleting that element (QA[i].dequeue(Array[count]); ) so that the second element is now the first. the problem is that the last element in the queue does not get put into the array. how am i supposed to access all the element in an apqueue?


    i also need help with this function:

    int GetDigit(int number,int k)
    //return kth digit of number

    but i have no idea how to do this one, can i convert the int to a string?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, how do you want your digits numbered? If your "ones" place is digit 1, your "tens" place is digit 2, "hundreds" = 3, etc, then you could just use:
    Code:
    int GetDigit(int number,int k){
    	return (int)(number/pow(10,k-1))%10;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    85
    thanks, the v, but does anyone know whats wrong with the QueuesToArray function?

  4. #4
    thats over my head

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    I see one big problem -- you're effectively incrementing the loop twice, because you're comparing to length(), which is decreased when you pop, and you are also incrementing your index variable. You also never use j.

    Not familiar with your template class, but I think this might be your problem: Change

    Code:
     for(int j=0; j<QA[i].length();j++){
    to

    Code:
    while(QA[i].length() >0){

Popular pages Recent additions subscribe to a feed