Issue with Creating a Pointer Array.

Doing an Assignment for class.

We get a list of 15 ints. Must put these into an array. Then must create a pointer array, that points to it's matching spot in the normal array.

arrayPtr[1] == array[1], arrayPtr[2] == array[2] etc.

We then use the supplied function (arrSelectSort) to sort the pointer array to now point to the array with the values in ascending order. (Proffesor supplied this code.)

Then we output the sorted pointer array, then output the non-sorted array.

I think I'm having an issue with having the pointer array point correctly.

CODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <iomanip>
using namespace std;

	//**********************************************************************
	// Definition of function arrSelectSort.                                         
	// This function performs an ascending order selection sort on  
	// array, which is an array of pointers. Each element of array    
	// points to an element of a second array. After the sort,            
	// array will point to the elements of the second array in            
	// ascending order.                                                                      
	//**********************************************************************

void arrSelectSort(int *array[ ], int size)
{
   int startScan, minIndex;
   int *minElem;

   for (startScan = 0; startScan < (size - 1); startScan++)
   {
      minIndex = startScan;
      minElem = array[startScan];
      for(int index = startScan + 1; index < size; index++)
      {
         if ( *(array[index] ) < *minElem)
         {
            minElem = array[index];
            minIndex = index;
         }
      }
      array[minIndex] = array[startScan];
      array[startScan] = minElem;
   }
}

void showArray(int array[ ], int size)
{
     cout << "The Donations, in there original order are: " << endl;
     for ( int i = 0; i < size; i++)
         cout << setw( 4 ) << array[ i ];
}

void showArrPtr(int *array[ ], int size)
{
     cout << "The Donations, in there ascending order are: " << endl;
     for ( int j = 0; j < size; j++)
         cout << setw( 4 ) << array[ j ];

}   


int main()
{
    
    const int NUM_SIZE = 15;
    int donations[ NUM_SIZE ] = { 5, 100, 5, 25, 10, 5, 25, 5, 5, 100, 10, 15, 10, 5, 10 };
    int *donationsPtr = donations;
    arrSelectSort(donationsPtr, NUM_SIZE);
    showArrPtr(donationsPtr, NUM_SIZE);
    cout << " " << endl;
    showArray(donations, NUM_SIZE);
    cout << " " << endl;
    system ("PAUSE");
    return EXIT_SUCCESS;
    
}


The Error Messages I recieve:
1
2
58 F:\ITP132\assign11.cpp cannot convert `int*' to `int**' for argument `1' to `void arrSelectSort(int**, int)' 
59 F:\ITP132\assign11.cpp cannot convert `int*' to `int**' for argument `1' to `void showArrPtr(int**, int)' 


This is being done in Dev-C++ 4.9.9.2.

Thanks in advance for any assitance!

Trevor
Last edited on
How are you passing the array into this function? I ask because the only times I've gotten that error message is when I attempted to pass an object to another function in the incorrect form.

If I remember correctly what you're telling the arrSelectSort function is that it's going to receive a pointer to an array rather than an actual array. Is that what you wanted?

You should probably post the section of code that's passing the array to these functions.
Whoops, should have made clearer in the first post.

arrSelectSort() is the function the professor gave us.
Topic archived. No new replies allowed.