pointer implementation of ADT list

I'm attempting to implement the ADT list by using pointers and my list is just supposed to contain integers but I'm confused on how to create the list in the main function and how to properly use some of the function calls such as insert

here is how i'm attempting to create the list in main, but I keep getting an error saying "request for member 'insert' in 'aList', which is of non member type 'list*'"

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

#include <iostream>
#include "list.h" // ADT list operations

using namespace std;

int main()
{

   ListItemType dataItem;
   bool         success;

   List *aList;

   try {
       *aList.insert(1);
       //aList.insert(2, 20);
       //aList.insert(3, 2);
       //aList.insert(4, 6);
       //aList.insert(5, 3);
       //aList.insert(6, 15);
   }
   catch( ListException & e1)
   {
          cerr << e1.what();
   }
   catch ( ListIndexOutOfRangeException & e2)
   {
       //handling the exception here
   }
   catch (...)
   {
         //handling all the other exceptions here
   }
  
   return 0;

}


firstly in my header file i'm not 100% sure if I have everything I need, the part I bolded is what I'm unsure about

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
67
68
69
70
71
72
73
#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED


/** @file ListAexcept.h */

#include "listExceptions.h"
#include <iostream>
#include <stack>
#include <list>

//const int MAX_LIST = 20;
typedef int ListItemType;

/** @class List
 * ADT list - Array-based implementation with exceptions */
class List
{
public:
   ~List();

   List();
   // destructor is supplied by compiler

   //@param aList the list to copy
   List(const List& aList);


   /** @throw None. */
   bool isEmpty() const;

   /** @throw None. */
   int getLength() const;

   /** @throw ListIndexOutOfRangeException  If index < 1 or index >
    *         getLength() + 1.
    *  @throw ListException  If newItem cannot be placed in the list
    *         because the array is full. */
   void insert(int newEntry);

   /** @throw ListIndexOutOfRangeException  If index < 1 or index >
    *         getLength(). */
   void remove(int index)
      throw(ListIndexOutOfRangeException);

   /** @throw ListIndexOutOfRangeException  If index < 1 or index >
    *         getLength(). */
   void retrieve(int index, ListItemType& dataItem) const
        throw(ListIndexOutOfRangeException);

   void operator= (const List & rhs);


   int largest(List a);

   int findLargest(List& a, int start, int end);

   //int find(int index) const;

private:
   /** array of list items */
      //ListItemType item[5];
    ListItemType items[1];

    // need to change insert and delete parameter to *listPointer
   /** number of items in list */


   int size;
   int *listPointer;

   int translate(int index) const;
}; // end List 


list.cpp, i believe this is all correct

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "list.h"  // header file
#include <cstddef>
#include <new>

List::List(): size(0)
{

}  // end default constructor


List::~List(){
    if (listPointer != NULL){
        delete [] listPointer;
        listPointer = NULL;
        size = 0;
    }
}

List::List(const List& aList)
    : size(aList.size)
{
    size = a.size;
    if (aList.size == 0)
        listPointer = NULL;
    else{
        //aList.size or is it just size?
        listPointer = new int [aList.size];
        for (int i=0;i<aList.size; i++)
            listPointer[i] = aList.listPointer[i];
  }

}

bool List::isEmpty() const
{
   return size == 0;
}  // end isEmpty

int List::getLength() const
{
   return size;
}  // end getLength


void List::retrieve(int index, ListItemType& dataItem) const
     throw(ListIndexOutOfRangeException)
{
   bool success;
   ListIndexOutOfRangeException outOfRange;

   success = (index >= 1) && (index <= size);

   if (!success) throw outOfRange;

   if (success)
      dataItem = items[translate(index)];
}  // end retrieve


void List::insert(int newEntry)
{
    if(size == 0){
        listPointer = new int[1];
        listPointer[0] = newEntry;
    }else{
        int *tmpPtr = new int[size];
        if(tmpPtr == NULL){
        cerr << "Copy constructor: memory allocation error (2)!\n";
        return;
        }
        for(int i = 0; i<size; i++){
            tmpPtr[i] = listPointer[i];
        }
        delete [] listPointer;
        listPointer = new int[size+1];
        if (listPointer == NULL ){
          cerr << "Copy constructor: memory allocation error (3)!\n";
          return;
          }
        for (i = 0; i < size; i++){
            listPointer[i] = tmpPtr[i];
        }
        listPointer[size] = newEntry;
        delete [] tmpPtr;
    }
        size += 1;

}

void List::remove(int index)
     throw(ListIndexOutOfRangeException)
{
   bool success;
   ListIndexOutOfRangeException outOfRange;

   success = (index >= 1) && (index <= size);

   if (!success) throw outOfRange;

   if (success)
   {  // delete item by shifting all items at positions >
      // index toward the beginning of the list
      // (no shift if index == size)
      for (int fromPosition = index + 1;
	   fromPosition <= size;
	   ++fromPosition)
         items[translate(fromPosition - 1)] = items[translate(fromPosition)];
      --size;  // decrease the size of the list by one
   }  // end if

}  // end remove

//done i think
void List::operator =(const List& rhs)
{

  //allocate space to *listPointer if needed
  if (size > 0)
      delete [] listPointer;  //release the old memory
      size = rhs.size;
  (*this).listPointer = new int [size];
  for (int i=0;i<size; i++)
          listPointer[i] = rhs.listPointer[i];

    //grades
}

int List::translate(int index) const
{
    return index-1;
}


any help is appreciated, thank you
or if anyone could direct me to an example of this implementation online (without using nodes), that would be great as well
Topic archived. No new replies allowed.