# Help writing Functions

Discussion in 'C' started by boat_58, Apr 1, 2011.

1. ### boat_58New Member

Joined:
Mar 27, 2011
Messages:
7
0
Trophy Points:
0
can someone please help me write these functions, i have looked online and i am having trouble finding how to write them. Thanks

class List
{

private:
int *a;
int count;
int capacity;

public:
List(); // create an empty list with capacity 0
List(int n); // create a list with capacity n
List(List l); // create a list similar to passed object l
~List(); // de-allocates memory from the list
void AddElement(int v); //add a number at the end of the list
void AddElement(int v,int p); // insert a number v at position p
void Sort(); // sorts all the numbers in the list
int *Retrieve(); // returns the pointer of “a”
List operator++(); // increate all the numbers in the list by 1
List operator--(); // decrease all the numbers in the list by 1
List operator+(int n); // increase all the numbers in the list by n
List operator-(int n); // decrease all the numbers in the list by n
List operator=(List l); // creates a duplicate list of l
friend List Combine(List l1,List l2); // creates and returns a new list, merging L1 and L2, so that the numbers in new list is sorted
}

------------------------------------------------------------------------------

List :: List()
{

}
List :: List(int n)
{

}

List :: List(List l)
{

}

List :: ~List()
{

}

{

}

void List :: AddElement(int v,int p)
{

}

void List :: Sort()
{

}

int *Retrieve()
{

}

List List :: operator++()
{

}

List List :: operator--()
{

}

List List :: operator+(int n)
{

}

List List :: operator-(int n)
{

}

List List :: operator=(List l)
{

}

List Combine(List l1,List l2)
{

}

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Just take them one at a time. What do you think a, count and capacity should be set to for an empty list? (At least have a guess)

3. ### boat_58New Member

Joined:
Mar 27, 2011
Messages:
7
0
Trophy Points:
0
i think i got some of it down but i am not sure if its right. for the first few i got this so far.

PHP:
``` List :: List(){a =0;count =0;Capacity=0;}List :: List(int n){a=new int[n];count = n;Capacity =n;}List :: List(List l) // This one i am not sure because i could not see any example on a passed object{a= new int[l]count =l;Capacity = l;}List :: ~List(){delete a;count=0;Capacity=0;} ```
Thats what i have gotten so far. I am having trouble with the two AddElements ones, can you help me on those ones, i will post what i have for sort and retrieve after i try for them.

Thanks

Joined:
Aug 6, 2004
Messages:
3,009