赞
踩
typedefcharCHAR;
struct DoubleQueue
{
CHAR m_data;
struct DoubleQueue* next;
struct DoubleQueue* prev;
};
typedefstruct DoubleQueue* DoubleLink;
void DoubleQueueInital();
void DoubleQueuePushFront(CHAR aElement);
CHAR DoubleQueuePopFront();
void DoubleQueuePushRear(CHAR aElement);
CHAR DoubleQueuePopRear();
void DoubleQueueFree();
staticDoubleLink Front,Tail;
void DoubleQueueInital()
{
Front= Tail= (DoubleLink)malloc(sizeof(*Front));
if (!Tail)
{
printf("DoubleQueueInital failed!!!!!");
return;
}
Tail->next =NULL;
Tail->prev =NULL;
Tail->m_data ='\0';
}
staticDoubleLink New(CHAR aElement)
{
DoubleLinkx = (DoubleLink)malloc(sizeof(*x));
if (!x)
{
printf("New failed!!!!!");
return NULL;
}
x->m_data = aElement;
return x;
}
void DoubleQueuePushFront(CHAR aElement)
{
DoubleLink x = New(aElement);
if (!x)
{
printf("DoubleQueuePushFront failed!!!!!");
return;
}
Front->prev = x;
x->next =Front;
x->prev =NULL;
Front = x;
}
CHAR DoubleQueuePopFront()
{
DoubleLinkx =Front;
if (!x)
{
printf("DoubleQueuePopFront failed!!!!!");
return '\0';
}
CHAR item = x->m_data;
Front= Front->next;
if(Front)
{
Front->prev = NULL;
free(x);
}
return item;
}
void DoubleQueuePushRear(CHAR aElement)
{
DoubleLink x = New(aElement);
if (!x)
{
printf("DoubleQueuePushRear failed!!!!!");
return;
}
Tail->next = x;
x->prev =Tail;
x->next =NULL;
Tail = x;
}
CHAR DoubleQueuePopRear()
{
DoubleLinkx =Tail;
if (!x)
{
printf("DoubleQueuePopRear failed!!!!!");
return '\0';
}
CHAR item = x->m_data;
Tail= Tail->prev;
if(Tail)
{
Tail->next = NULL;
free(x);
}
return item;
}
void DoubleQueueFree()
{
while (Front)
{
DoubleLinkx =Front;
printf("%c",x->m_data);
Front = Front->next;
free(x);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。