#include<stdio.h>
class node
{
public:
int data;
node *plink;
};
class List
{
public:
node *head;
public:
List()
{
head = NULL;
}
~List()
{
node *temp;
while(head)
{
temp = head->plink;
delete head;
head = temp;
}
}
bool Insert(int k, int e)
{
node *temp;
temp = head;
for(int i=1; (i<k)&&temp; i++)
temp = temp->plink;
node *new_node = new node;
new_node->data = e;
if(k)
{
new_node->plink = temp->plink;
temp->plink = new_node;
}
else
{
new_node->plink = head;
head = new_node;
}
return true;
}
bool Delete(int k)
{
if(k == 1)
{
head = head->plink;
return true;
}
node *temp;
temp = head;
for(int i=1; (i<(k-1))&&temp; i++)
temp = temp->plink;
node *tempDel;
tempDel = temp->plink;
temp->plink = tempDel->plink;
return true;
}
int get(int k)
{
node *temp;
temp = head;
for(int i=1; (i<k)&&temp; i++)
temp = temp->plink;
return temp->data;
}
int Length()
{
int length = 0;
node *temp;
temp = head;
while(temp)
{
length++;
temp = temp->plink;
}
return length;
}
bool IsEmpty()
{
return head==NULL;
}
};
int main()
{
List list;
list.Insert(0, 1);
list.Insert(0, 2);
list.Insert(1, 3);
list.Insert(1, 4);
list.Insert(1, 5);
list.Delete(2);
list.Delete(3);
for(int i=1; i<=list.Length(); i++)
{
printf("%d/n", list.get(i));
}
}