# Thread: What do these Methods do?? Take a look

1. ## What do these Methods do?? Take a look

Can anyone help me and tell me what Method1, Method2, Method3, Method4, Method5 do?

template <class T>
bool List<T> ::Method1 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (first == -1)
first = last = 0;
else if (first == 0)
first = capacity -1;
else
first --;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method2 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (last == -1)
first = last = 0;
else
last = (last +1) % capacity;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method3 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else
first = (first +1) % capacity;
return true;
}

template <class T>
bool List<T> ::Method4 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else if (last ==0)
last = capacity -1;
else
last --;

return true;
}

template <class T>
bool List<T> ::Method5 (const size_t & new_capacity)
{
T * temp = data;
data = new T[new_capacity];
if(data == NULL)
{
data = temp;
return false;
}
if (used >0)
{
int j =first;
int k = (new_capacity - used) /2;
first =k;
last = first + used -1;
for (int i =0; i <used ; i++)
{
data[k] = temp[j];
j = (j+1) % capacity;
k++;
}
}
capacity = new_capacity;
delete []temp;
return true;
}

2. We will not do your homework for you. Sorry.

3. sorry to say, but its not homework...

4. edit ur post to use code tags and then I might take a look at it..

5. Code:
```template <class T>
bool List<T> ::Method1 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (first == -1)
first = last = 0;
else if (first == 0)
first = capacity -1;
else
first --;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method2 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (last == -1)
first = last = 0;
else
last = (last +1) % capacity;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method3 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else
first = (first +1) % capacity;
return true;
}

template <class T>
bool List<T> ::Method4 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else if (last ==0)
last = capacity -1;
else
last --;

return true;
}

template <class T>
bool List<T> ::Method5 (const size_t & new_capacity)
{
T * temp = data;
data = new T[new_capacity];
if(data == NULL)
{
data = temp;
return false;
}
if (used >0)
{
int j =first;
int k = (new_capacity - used) /2;
first =k;
last = first + used -1;
for (int i =0; i <used ; i++)
{
data[k] = temp[j];
j = (j+1) % capacity;
k++;
}
}
capacity = new_capacity;
delete []temp;
return true;
}```

6. Originally posted by gqchynaboy
sorry to say, but its not homework...
I find it very hard to believe that any program that was not created for learning purposes would use horrible function names such as Method1, Method2, etc. Let us know where the program came from, if it is not homework.

7. we don't mind if it is homework, as long as you show effort and don't ask anyone to write it for you.

8. thanks thats all i was asking for...

9. Method 1 “InsertFirst”
If there is no space, Method 5 is called to create new space.
In addition, Method 1 adds integers to the beginning of the list.

Method 2 “InsertLast”
If there is no space, Method 5 is called to create new space.
In addition, Method 2 adds integers to the end beginning of the list.

Method 3 “RemoveFirst”
If there is no space, Method 5 is called to create new space.
In addition, Method 3 removes the integers from the beginning of the list.

Method 4 “RemoveLast”
If there is no space, Method 5 is called to create new space.
In addition, Method 4 removes the last integers of the list