#include <iostream>
struct IntNode{
int data;
IntNode* next;
IntNode():data(0), next(0){
}
IntNode(int data, IntNode* next):data(data), next(next){
}
};
class SGList{
public :
SGList();
~SGList();
int size() const;
bool empty() const;
void print(std::ostream& oss) const;
void insert(const int& item);
protected :
int count;
IntNode* head;
IntNode* set_position(int pos) const;
};
SGList::SGList():count(0), head(NULL){
}
SGList::~SGList(){
IntNode* old_head = head;
head = old_head->next;
delete old_head;
}
bool SGList::empty() const{
return count == 0;
}
int SGList::size() const{
return count;
}
void SGList::print(std::ostream& oss) const{
IntNode* temp = head;
while(temp->next != NULL){
oss << temp->data << " ";
temp = temp->next;
}
oss << '\n';
}
IntNode* SGList::set_position(int pos) const{
IntNode* q = head;
for(int x = 0; x < pos; ++x){
q = q->next;
}
return q;
}
void SGList::insert(const int& item){
IntNode* new_head = new IntNode(item, head);
head = new_head;
}
int main(){
SGList aList;
for(int x = 0; x < 5; ++x){
aList.insert(x);
}
}