当前位置:   article > 正文

c语言链表实现双端队列,使用双向链表实现双端队列

双向链表实现队列c语言

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);

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/660691
推荐阅读
相关标签
  

闽ICP备14008679号