利用前面写的双向循环链表库文件中的功能,实现队列存储结构
库中并非所用功能都用到,为实现方便出队,库增加了依据地址删除链表元素的功能(包含头节点,头节点的下一节点替代)
主函数代码
#include "dnode_lib.h"
typedef struct Nqueue{
pdnode p_front;
pdnode p_rear;
}nqueue, *pnqueue;
void init_node_queue(pnqueue ptr, int num);
//creat a queue with only one element,value is num;
//use library :dnode_lib.c and dnode_lib.h
//queue's p_front and p_rear point to the same one node element
void en_nqueue(pnqueue ptr, int val_f);
//add one element to queue's tail
//use library :dnode_lib.c and dnode_lib.h
//ptr is target queue, val_f is value to enter queue
int dequeue(pnqueue ptr);
//dequeue
//front element will be removed ,that element's value is returned
//this function calls "del_dnode_addr(pdnode * p_head, pdnode p_dnode)"
//that called function will delete any element pointed by its argc"* p_head",including node's head
//after deleted ,free that element's memory
void show_nqueue(pnqueue ptr);
//show all queue's element value
int main(void){
nqueue n_queue;
pnqueue p_nqueue = &n_queue;
int num;
printf("input first val of queue\n");
scanf("%d",&num);
init_node_queue(p_nqueue, num);
printf("init val is %d\n",p_nqueue->p_front->val);
en_nqueue(p_nqueue, 99);
en_nqueue(p_nqueue, 98);
en_nqueue(p_nqueue, 97);
en_nqueue(p_nqueue, 96);
show_nqueue(p_nqueue);
printf("__________apd group done____________\n") ;
dequeue(p_nqueue);
show_nqueue(p_nqueue);
dequeue(p_nqueue);
show_nqueue(p_nqueue);
dequeue(p_nqueue) ;
show_nqueue(p_nqueue);
dequeue(p_nqueue) ;
show_nqueue(p_nqueue);
dequeue(p_nqueue) ;
show_nqueue(p_nqueue);
printf("__________del group done____________\n") ;
en_nqueue(p_nqueue, 99);
show_nqueue(p_nqueue);
return 0;
}
void init_node_queue(pnqueue ptr, int num){
pdnode p_dnode = init_stal_dnode();
p_dnode->val = num;
ptr->p_front = p_dnode;
ptr->p_rear = p_dnode;
ptr->p_rear->fwd = p_dnode;
ptr->p_rear->bwd = p_dnode;
printf("init queue done \n");
}
void en_nqueue(pnqueue ptr, int val_f){
pdnode p_dnode = ptr->p_front;
ptr->p_rear = apd_dnode(p_dnode, val_f);
printf("append queue :val is %d\n",ptr->p_rear->val);
}
int dequeue(pnqueue ptr){
if(ptr->p_front