#include <iostream>
using namespace std;
class CustomList{
private:
//**********************************************
typedef struct s_list
{
string content;
s_list *next;
} t_list;
//**********************************************
t_list * _first;
public:
CustomList(){
_first = NULL;
}
//**********************************************
void push(string _content){
t_list * list = NULL;
list = getLast();
if (list)
list->next = newList(_content);
else
_first = newList(_content);
}
// * * * * * * * * * * * * * * * * * * * * * * * *
t_list * newList(string _content){
t_list *newL = NULL;
newL = new t_list;
newL->content = _content;
newL->next = NULL;
cout<<"CREATE NEW LIST -> CONTENT : " <<newL->content<<endl;
return (newL);
}
// * * * * * * * * * * * * * * * * * * * * * * * *
t_list * getLast(){
t_list * list = NULL;
list = _first;
while(list && list->next)
list = list->next;
return (list);
}
// * * * * * * * * * * * * * * * * * * * * * * * *
~CustomList(){
t_list * toDel = NULL;
while(_first){
toDel = _first;
cout<<"DELTETING LIST -> CONTENT : " <<toDel->content<<endl;
_first = _first->next;
if (toDel)
delete toDel;
}
}
};
int main() {
CustomList * customList = new CustomList();
customList->push("fisrt list");
customList->push("second list");
customList->push("third list");
cout<<"- - - - - - - - - - - - - - - - - - - - - " <<endl;
delete customList;
return 0;
}
Comments
Leave a comment