![]() |
Help writing Functions
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) { } 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) { } |
Re: Help writing Functions
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)
|
Re: Help writing Functions
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 Code:
Thanks |
Re: Help writing Functions
Your copy constructor is not correct; l is a List, not an integer. Use l.count and l.Capacity instead.
Where are you stuck on the AddElements ones? For this, you would just need to identify the next free slot in the array, copy the value and increase count, having checked of course that Capacity has not been exceeded, correct? |
| All times are GMT +5.5. The time now is 23:22. |