template<typename type>
class List
{
private:
type list[];
public:
type get(int);
void add(type);
void remove(int);
int size();
bool isEmpty();
bool contains(type);
void trim();
List();
~List();
};
template<typename type>
List<type>::List()
{
list = new type[1];
}
template<typename type>
List<type>::~List()
{
list = NULL;
}
template<typename type>
type List<type>::get(int index)
{
return list[index];
}
template<typename type>
void List<type>::add(type obj)
{
type temp[] = new type[list.length + 1];
for(int ti = 0; ti < size(); ti++)
temp[ti] = (Object)list[ti];
temp[list.length] = element;
}
template<typename type>
void List<type>::remove(int index)
{
list[index] = NULL;
}
template<typename type>
int List<type>::size()
{
return (sizeof(list) / sizeof(list[0])) - 1 > 0 ?
sizeof(list) / sizeof(list[0]) :
0;
}
template<typename type>
bool List<type>::isEmpty()
{
return size() > 0;
}
template<typename type>
bool List<type>::contains(type obj)
{
for(int i = 0; i < list.length; i++)
if(list[i]== obj)
return true;
return false;
}
template<typename type>
void List<type>::trim()
{
int count = 0;
for(int i = 0; i < size(); i++)
{
if(!list[i] == NULL)
count++;
}
if(count > 0)
{
type temp[] = new type[count];
count = 0;
for(int i = 0; i < count; i++)
{
if(!list[i] == NULL)
{
temp[count] = list[i];
count++;
}
}
}
}
Copyright © 2025, NextGenUpdate.
All Rights Reserved.