c语言队列存入文件,队列实现文件C语言

/*Uiversal_queue.c -- 队列实现文件*/

#include "Uiversal_queue.h"

/*Proclaim local functions*/

static Node * makeNode (const Item * const pi) ;

/*Define interface functions*/

Bool Initialize_Q (Queue * const pq)

{

*pq = (struct queue *) malloc (sizeof (struct queue)) ;

if (NULL == *pq)

return FALSE ;

(*pq) -> front = (*pq) -> rear = NULL ;

(*pq) -> current = 0 ;

return TRUE ;

}

Bool IsEmpty_Q (const Queue * const pq)

{

return 0 == (*pq) -> current ;

}

Bool Insert_Q (Queue * const pq, const Item * const pi)

{

Node * new_node ;

new_node = makeNode (pi) ;

if (NULL == new_node)

return FALSE ;

else

{

if (IsEmpty_Q (pq))

(*pq) -> front = (*pq) -> rear = new_node ;

else

{

(*pq) -> rear -> next = new_node ;

(*pq) -> rear = (*pq) -> rear -> next ;

}

(*pq) -> current++ ;

return TRUE ;

}

}

Bool Delete_Q (Queue * const pq, Item * const pi)

{

Node * scan, * temp ;

if (IsEmpty_Q (pq))

return FALSE ;

else if (1 == (*pq) -> current)

{

*pi = (*pq) -> front -> item ;

free ((*pq) -> front) ;

(*pq) -> front = (*pq) -> rear = NULL ;

(*pq) -> current-- ;

return TRUE ;

}

else

{

scan = (*pq) -> front ;

if (pi -> leavings == scan -> item.leavings)

{

*pi = (*pq) -> front -> item ;

(*pq) -> front = (*pq) -> front -> next ;

free (scan) ;

(*pq) -> current-- ;

return TRUE ;

}

else

{

while (scan)

{

if (pi -> leavings == scan -> next -> item.leavings)

break ;

else

scan = scan -> next ;

}

if (pi -> leavings == scan -> next -> item.leavings)

{

temp = scan -> next ;

scan -> next = scan -> next -> next ;

free (temp) ;

(*pq) -> current-- ;

return TRUE ;

}

else

return FALSE ;

}

}

}

void Traversal_Q (const Queue * const pq, void (* pfun) (const Item * const pi))

{

Node * scan ;

scan = (*pq) -> front ;

while (scan)

{

(* pfun) (&scan -> item) ;

scan = scan -> next ;

}

}

void Release_Q (const Queue * const pq)

{

Node * scan, * temp ;

scan = (*pq) -> front ;

while (scan)

{

temp = scan ;

scan = scan -> next ;

free (temp) ;

}

}

/*Define local functions*/

static Node * makeNode (const Item * const pi)

{

Node * new_node ;

new_node = (Node *) malloc (sizeof (Node)) ;

if (NULL == new_node)

return NULL ;

else

{

new_node -> item = *pi ;

new_node -> next = NULL ;

return new_node ;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值