#include <iostream>
struct node {
int data;
node *next;
};
class LinkedList
{
private:
node *head, *tail;
public:
LinkedList() {
head = NULL;
tail = NULL;
}
void AddNode(int n) {
node *tmp = new node;
tmp->data = n;
tmp->next = NULL;
if (head == NULL) {
head = tmp;
tail = tmp;
}
else {
tail->next = tmp;
tail = tail->next;
}
}
void Print() {
node *tmp = head;
while (tmp != NULL) {
std::cout << tmp->data << "\n";
tmp = tmp->next;
}
}
void Delete() {
node *tmp = head;
while (tmp != NULL) {
node *dl = tmp;
tmp = tmp->next;
delete dl;
}
}
};
int main()
{
LinkedList ll;
ll.AddNode(1);
ll.AddNode(2);
ll.AddNode(3);
ll.Print();
ll.Delete();
}
/*
run:
1
2
3
*/