#include <iostream>
using namespace std;
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
bool InitList_1(LinkList &L){
L=NULL;
return true;
}
bool Empty_1(LinkList L){
return (L==NULL);
}
bool InitList(LinkList &L){
L=(LNode *)malloc(sizeof(LNode));
if(L==NULL)
return false;
L->next = NULL;
return true;
}
bool Empty(LinkList L){
if(L->next==NULL)
return true;
else
return false;
}
bool ListInsert_1(LinkList &L,int i,int e){
if(i<1)
return false;
LNode *s=(LNode *)malloc(sizeof(LNode));
s->data=e;
if(i==1){
s->next=L;
L=s;
return true;
}
LNode *p=L;
for(int j=1;p!=NULL&&j<i-1;j++)
p=p->next;
if(p==NULL)
return false;
s->next=p->next;
p->next=s;
return true;
}
bool InsertNextNode(LNode *p,int e){
if(p==NULL)
return false;
LNode *s=(LNode *)malloc(sizeof(LNode));
if(s==NULL)
return false;
s->data=e;
s->next=p->next;
p->next=s;
return true;
}
bool ListInsert(LinkList &L,int i,int e){
if(i<1)
return false;
LNode *p;
int j=0;
p=L;
while(p!=NULL&&j<i-1){
p=p->next;
j++;
}
InsertNextNode(p,e);
return true;
}
bool InsertPriorNode(LNode *p,int e){
if(p==NULL)
return false;
LNode *s=(LNode *)malloc(sizeof(LNode));
if(s==NULL)
return false;
s->data=p->data;
s->next=p->next;
p->next=s;
p->data=e;
return true;
}
bool ListDelete(LinkList &L,int i,int &e){
if(i<1)
return false;
LNode *p=L;
for(int j=0;p!=NULL&&j<i-1;j++)
p=p->next;
if(p==NULL)
return false;
LNode *q=p->next;
p->next=q->next;
e=q->data;
free(q);
return true;
}
bool DeleteNode(LNode *p){
if(p==NULL)
return false;
LNode *q=p->next;
p->next=q->next;
p->data=q->data;
free(q);
return true;
}
LNode *GetElem(LinkList L,int i){
if(i<1)
return NULL;
LNode *p=L;
int j=0;
while(p!=NULL&&j<i){
p=p->next;
j++;
}
return p;
}
LNode *LocateElem(LinkList L,int e){
LNode *p=L->next;
while(p!=NULL&&p->data!=e)
p=p->next;
return p;
}
int Length(LinkList L){
LNode *p=L->next;
int len=0;
while(p!=NULL){
p=p->next;
len++;
}
return len;
}
LinkList List_TailInsert(LinkList &L){
int x;
L=(LinkList)malloc(sizeof(LNode));
LNode *s,*r=L;
scanf("%d",&x);
while(x!=9999){
s=(LNode *)malloc(sizeof(LNode));
s->data=x;
r->next=s;
r=s;
scanf("%d",&x);
}
r->next=NULL;
return L;
}
LinkList List_HeadInsert(LinkList &L){
int x;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
LNode *s;
scanf("%d",&x);
while(x!=9999){
s=(LNode *)malloc(sizeof(LNode));
s->data=x;
s->next=L->next;
L->next=s;
scanf("%d",&x);
}
return L;
}
LinkList List_HeadInsert_1(LinkList &L){
int x;
LNode *s;
L=NULL;
scanf("%d",&x);
while(x!=9999){
s=(LNode *)malloc(sizeof(LNode));
s->data=x;
s->next=L;
L=s;
scanf("%d",&x);
}
return L;
}
typedef struct DNode{
int data;
struct DNode *prior,*next;
}DNode,*DLinkList;
bool InitDLinkList(DLinkList &L){
L=(DNode *)malloc(sizeof(DNode));
if(L==NULL)
return false;
L->prior=NULL;
L->next=NULL;
return true;
}
bool InsertNextDNode(DNode *p,DNode *s){
if(p==NULL||s==NULL)
return false;
s->next=p->next;
s->prior=p;
if(p->next!=NULL){
p->next->prior=s;
}
p->next=s;
return true;
}
bool DeleteNextDNode(DNode *p){
DNode *q=p->next;
if(p==NULL||q==NULL)
return false;
p->next=q->next;
if(q->next!=NULL)
q->next->prior=p;
free(q);
return true;
}
void DestoryDList(DLinkList &L){
while(L->next!=NULL)
DeleteNextDNode(L);
free(L);
L=NULL;
}
void Travel(DNode *p){
while(p!=NULL)
p=p->next;
while(p!=NULL)
p=p->prior;
while(p->prior!=NULL)
p=p->prior;
}
bool InitCycleList(LinkList &L){
L=(LNode *)malloc(sizeof(LNode));
if(L==NULL)
return false;
L->next=L;
return true;
}
bool CycleEmpty(LinkList L){
return (L->next==L);
}
bool CycleisTail(LinkList L,LNode *p){
return (p->next==L);
}
bool InitCycleDLinkList(DLinkList &L){
L=(DNode *)malloc(sizeof(DNode));
if(L==NULL)
return false;
L->prior=L;
L->next=L;
return true;
}
bool CycleDEmpty(DLinkList L){
return (L->prior==L&&L->next==L);
}
bool CycleDisTail(LinkList L,LNode *p){
return (p->next==L);
}
#define MaxSize 10
typedef struct{
int data;
int next;
}SLinkList[MaxSize];
bool InitSLinkList(SLinkList &a){
a[0].next=-1;
return true;
}
int main()
{
int *a;
int c=20;
a=&c;
int *b=a;
cout << b << endl;
cout <<a << endl;
cout << *a << endl;
cout << *b << endl;
return 0;
}
|