
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
Node *prev;
};
class LinkList
{
public:
LinkList();
~LinkList();
Node *getHead()
{
return head;
}
int operator[](int i);
int lengthlist(Node* L);
void push_back(int &val);
int Erase (Node* L,int i);
void transform();
private:
Node *head;
};
LinkList::LinkList()
{
head=new Node;
head->next=0;
}
LinkList::~LinkList()
{
Node *ptr;
if(head == NULL)
return;
while(head != NULL)
{
ptr = head->next;
head->next = ptr->next;
delete ptr;
}
}
int LinkList::operator[](int i)
{
Node *ptr = head;
int count=0;
while(count<i && ptr!=0)
{
count=count+1;
ptr=ptr->next;
}
if(ptr!=0)
return ptr->data;
else
return -1;
}
void LinkList::push_back(int &val)
{
Node *p=new Node;
p=head->next;
while(p->next!=0)
{
p=p->next;
}
Node *q=new Node;
q->data=val;
q->prev=p->prev;
p->prev->next=q;
q->next=p;
p->prev=q;
}
int LinkList:: lengthlist(Node* L){
Node* p=head;
int count=0;
while(p!=L){
p=p->next;
count++;
}
return count;
}
int LinkList::Erase (Node* L,int i){
Node* p=L;
int j=0;
if(i>lengthlist(L)){
return 0;
}
while(j<i){
p=p->next; ++j;
}
p->prev->next=p->next;
free(p);
return 1;
}
void LinkList:: transform()
{
Node *s=head->next;
Node *t=s->next;
while(t->next!=0)
{
if(s->data>t->data)
s->data=t->data;
t=t->next;
}
}
void main()
{
LinkList A;
int elem=4;
A.push_back(elem);
elem=7;
A.push_back(elem);
cout<<A[0]<<endl;
cout<<A[1]<<endl;
}
using namespace std;
class Node
{
public:
int data;
Node *next;
Node *prev;
};
class LinkList
{
public:
LinkList();
~LinkList();
Node *getHead()
{
return head;
}
int operator[](int i);
int lengthlist(Node* L);
void push_back(int &val);
int Erase (Node* L,int i);
void transform();
private:
Node *head;
};
LinkList::LinkList()
{
head=new Node;
head->next=0;
}
LinkList::~LinkList()
{
Node *ptr;
if(head == NULL)
return;
while(head != NULL)
{
ptr = head->next;
head->next = ptr->next;
delete ptr;
}
}
int LinkList::operator[](int i)
{
Node *ptr = head;
int count=0;
while(count<i && ptr!=0)
{
count=count+1;
ptr=ptr->next;
}
if(ptr!=0)
return ptr->data;
else
return -1;
}
void LinkList::push_back(int &val)
{
Node *p=new Node;
p=head->next;
while(p->next!=0)
{
p=p->next;
}
Node *q=new Node;
q->data=val;
q->prev=p->prev;
p->prev->next=q;
q->next=p;
p->prev=q;
}
int LinkList:: lengthlist(Node* L){
Node* p=head;
int count=0;
while(p!=L){
p=p->next;
count++;
}
return count;
}
int LinkList::Erase (Node* L,int i){
Node* p=L;
int j=0;
if(i>lengthlist(L)){
return 0;
}
while(j<i){
p=p->next; ++j;
}
p->prev->next=p->next;
free(p);
return 1;
}
void LinkList:: transform()
{
Node *s=head->next;
Node *t=s->next;
while(t->next!=0)
{
if(s->data>t->data)
s->data=t->data;
t=t->next;
}
}
void main()
{
LinkList A;
int elem=4;
A.push_back(elem);
elem=7;
A.push_back(elem);
cout<<A[0]<<endl;
cout<<A[1]<<endl;
}