📄 pqueues.h
字号:
#pragma PQueues
#include <SYSTEM.h>
#include <PLinks.h>
/********************************* Link **********************************)
(* *)
(* The first field of any RECORD to be inserted into a Queue must be *)
(* of TYPE Link. This field will contain all pointer and priority *)
(* information used by the queues MODULE routines. *)
(* *)
(*************************************************************************)
(****************************** Queue ************************************)
(* *)
(* A variable of type Queue serves as the base of a doubly-linked list *)
(* of queue entry RECORDS. *)
(* *)
(*************************************************************************/
typedef struct {
Link head;
Link tail;
} Queue;
/********************************* AddAfter ******************************)
(* *)
(* This routine adds the RECORD at the specified address to a *)
(* Queue immediately following an old RECORD already in the *)
(* Queue. The priority of the new RECORD is not affected. *)
(* *)
(*************************************************************************/
void AddAfter(Queue &q,Link &next, Link &old);
/*********************************** AddBefore ***************************)
(* *)
(* This routine adds the RECORD at the specified address to a *)
(* Queue immediately preceeding an old RECORD already in the *)
(* Queue. The priority of the new RECORD is not changed. *)
(* *)
(*************************************************************************/
void AddBefore(Queue &q,Link &prev, Link &old);
/***************************** AddHead ***********************************)
(* *)
(* This routine adds the RECORD at the specified address to the *)
(* head of the specified Queue. The priority of the RECORD is *)
(* unchanged. *)
(* *)
(*************************************************************************/
void AddHead(Queue &q,Link &l);
/********************************* AddTail *******************************)
(* *)
(* This routine adds the RECORD at the specified address to the tail *)
(* of the specified Queue. The priority of the RECORD is unchanged. *)
(* *)
(*************************************************************************/
void AddTail(Queue &q,Link &l);
/******************************** AddPriority ****************************)
(* *)
(* This routine adds the RECORD at the specified address to the *)
(* specified Queue just before the first record already present with a *)
(* lower priority. In other words, the RECORDs in the Queue will be *)
(* ordered from highest (numerically greatest) to lowest priority with *)
(* RECORDs of equal priority ordered in first-in-first-out fashion. *)
(* *)
(*************************************************************************/
void AddPriority(Queue &q, Link &l, int prio);
/***************************** ChangePriority ****************************)
(* *)
(* This routine changes the priority of a queue record by moving it to *)
(* a new position, if necessary. If the new priority is the same as the *)
(* old, the queue position is not changed. *)
(* *)
(*************************************************************************/
void ChangePriority(Queue &q,Link &l, int prio);
/*************************************************************************)
(************************ Remove PROCEDUREs ******************************)
(*************************************************************************)
(******************************* RemoveHead ******************************)
(* *)
(* This routine removes the RECORD from the head of the specified Queue *)
(* and returns its address. If the Queue is empty then NIL is returned. *)
(* *)
(*************************************************************************/
ADDRESS RemoveHead(Queue &q);
/******************************** RemoveTail *****************************)
(* *)
(* This routine removes the RECORD from the tail of the specified Queue *)
(* and returns its address. If the Queue is empty then NIL is returned. *)
(* *)
(*************************************************************************/
ADDRESS RemoveTail(Queue &q);
/******************************* RemoveThis ******************************)
(* *)
(* This routine removes the RECORD at the specified address from its *)
(* Queue. This routine does NOT scan the Queue to ensure that *)
(* such a RECORD really exists -- use FindThis for that purpose. *)
(* *)
(*************************************************************************/
void RemoveThis(Queue &q,Link &old);
/*************************************************************************)
(*********************** Look PROCEDUREs *********************************)
(*************************************************************************)
(****************************** LookHead *********************************)
(* *)
(* This routine returns the address of the RECORD at the head of the *)
(* specified Queue WITHOUT removing the RECORD from the Queue. If the *)
(* Queue is empty then NIL is returned. *)
(* *)
(*************************************************************************/
ADDRESS LookHead(Queue &q);
/****************************** LookTail *********************************)
(* *)
(* This routine returns the address of the RECORD at the tail of the *)
(* specified Queue WITHOUT removing the RECORD from the Queue. If the *)
(* Queue is empty then NIL is returned. *)
(* *)
(*************************************************************************/
ADDRESS LookTail(Queue &q);
/******************************** LookNext *******************************)
(* *)
(* This routine returns the address of the next RECORD in the specified *)
(* Queue following the old record already in the Queue. If the old *)
(* RECORD is the last RECORD in the Queue (and hence there is no next *)
(* RECORD) then NIL is returned. *)
(* *)
(*************************************************************************/
pLink LookNext(Queue &q,pLink old);
/********************************* LookPrevious **************************)
(* *)
(* This routine returns the address of the previous record in the *)
(* specified Queue immediately preceeding the old record already in the *)
(* Queue. If the old RECORD is the first RECORD in the Queue (and *)
(* hence there is no previous RECORD) then NIL is returned. *)
(* *)
(*************************************************************************/
pLink LookPrevious(Queue &q,pLink old);
/*************************************************************************)
(************************* Find PROCEDUREs *******************************)
(*************************************************************************)
(********************************** FindThis *****************************)
(* *)
(* This routine scans the specified Queue for the RECORD at the *)
(* specified address. If the RECORD is found then its position *)
(* 1 2 3 in the queue is returned; zero if not present. *)
(* *)
(*************************************************************************/
unsigned int FindThis(Queue &q,Link &old);
/*************************************************************************)
(************************* Initialize PROCEDUREs *************************)
(*************************************************************************)
(******************************* InitializeQueue *************************)
(* *)
(* This routine initializes the specified Queue base variable to the *)
(* empty state. New RECORDs may then be added or removed from the *)
(* Queue using the queues MODULE routines. *)
(* *)
(*************************************************************************/
void InitializeQueue(Queue &q);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -