约定:
<必选参数> [可选参数]
默认传入变量名,有?包裹代表可传入数值、可传入变量名。
返回值在!ErrorLevel!,默认0为成功,其它为失败。
库名:线性表
实现:
链式储存结构-单向链表(含头结点)。
(Linked Storage Structure - Singly Linked List)
结点字段:
Data 储存结点的数据。
Next 指向结点对应的下一个结点。
用法:Call LinearList_LSS_SLL 函数名 参数
函数:
:Init <ListName>
建立空的线性表。
返回后,变量ListName即为头指针,头指针指向头结点。
:Clear <?ListName?>
清空线性表。
elete <ListName>
删除线性表。
变量ListName也会被删除。
:IsEmpty <?ListName?>
判断线性表是否为空表。
:GetLength <?ListName?>
返回线性表的元素个数(不计头结点)。
:GetNextNodePtr <?NodePtr?>
返回下一个结点的指针,0表示不存在下个结点。
:InsertNextNode <?NodePtr?> <VarToInsert>
在当前指针指向结点后插入新结点。
将返回新结点的指针。
:DeleteNextNode <?NodePtr?> [VarToSaveNextNodeElemValue]
删除指针指向结点的后一结点,可以返回后一结点的值。
:GetNodeElem <?NodePtr?> <VarToSaveElemValue>
得到指针指向结点的值。
:EditNodeElem <?NodePtr?> <VarToReplaceElemValue>
修改指针指向结点的值。
LinearList_SSS.txt复制代码
- ::Code by OldLiu
- ::老刘编写
- ::Start
- Set "_TMP_Arguments_=%*"
- If "!_TMP_Arguments_:~,1!" Equ ":" (
- Set "_TMP_Arguments_=!_TMP_Arguments_:~1!"
- )
- Call :LinearList_LSS_SLL_!_TMP_Arguments_!
- Set _TMP_Arguments_=
- Goto :Eof
- ::LinearList_LSS_SLL Begin
- :LinearList_LSS_SLL_GetRandom
- Set /A ErrorLevel=%random%%%10000+%random%*10000
- If !ErrorLevel! Equ 0 Goto GetRandom
- If Defined Memory[!ErrorLevel!].Data Goto GetRandom
- Goto :Eof
- :LinearList_LSS_SLL_Init ListName
- Call :LinearList_LSS_SLL_GetRandom
- Set /A %~1=ErrorLevel
- Set Memory[!ErrorLevel!].Data=ListHead
- Set /A Memory[!ErrorLevel!].Next=0
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Clear ListName
- Call :LinearList_LSS_SLL_DeleteNextNode "%~1"
- If !ErrorLevel! Equ 0 Goto :LinearList_LSS_SLL_Clear
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Delete ListName
- Call :LinearList_LSS_SLL_Clear "%~1"
- Set Memory[!%~1!].Data=
- Set Memory[!%~1!].Next=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetLength ListName
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_=0
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=%~1
- :LinearList_LSS_SLL_GetLength_Loop
- Call :LinearList_LSS_SLL_GetNextNodePtr _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=ErrorLevel
- If !_LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_! Neq 0 (
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_+=1
- Goto LinearList_LSS_SLL_GetLength_Loop
- )
- Set /A ErrorLevel=_LinearList_LSS_SLL_GetLength_TMP_ListLength_
- Set _LinearList_LSS_SLL_GetLength_TMP_ListLength_=
- Set _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=
- Goto :Eof
- :LinearList_LSS_SLL_IsEmpty ListName
- :LinearList_LSS_SLL_GetNextNodePtr NodePtr
- Set /A _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=%~1
- Set /A ErrorLevel=Memory[!_LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_!].Next
- Set _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_InsertNextNode NodePtr VarToInsert
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next
- Call :LinearList_LSS_SLL_GetRandom
- Set /A Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next=ErrorLevel
- Set /A Memory[!ErrorLevel!].Next=_LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_
- Set "Memory[!ErrorLevel!].Data=!%~2!"
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_DeleteNextNode NodePtr [VarToSaveNextNodeElemValue]
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next
- If !_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_! Equ 0 (
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Set /A Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next
- If "%~2" Neq "" Call Set "%~2=%%Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data%%"
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next=
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetNodeElem NodePtr VarToSaveElemValue
- Set /A LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=%~1
- Call Set "%~2=%%Memory[!LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_!].Data%%"
- Set LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_EditNodeElem NodePtr VarToReplaceElemValue
- Set /A LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=%~1
- Set "Memory[!LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_!].Data=!%~2!"
- Set LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- ::LinearList_LSS_SLL End
库名:线性表
实现:
顺序储存结构
(Sequence Storage Structure)
用法:Call LinearList_SSS 函数名 参数
函数:
:Init <ListName> <?MaxLength?>
初始化操作,建立一个空的线性表。
表最多可储存MaxLength个元素。
:Clear <ListName>
清空线性表。
:Delete <ListName>
删除线性表。
:GetElem <ListName> <?Index?> <VarToReturn>
将线性表中第Index(从1开始)个元素的值返回。
:EditElem <ListName> <?Index?> <VarToReplaceWith>
修改线性表中第Index个位置的元素值。
Queue_LSS.txt复制代码
- ::Code by OldLiu
- ::老刘编写
- ::Start
- Set "_TMP_Arguments_=%*"
- If "!_TMP_Arguments_:~,1!" Equ ":" (
- Set "_TMP_Arguments_=!_TMP_Arguments_:~1!"
- )
- Call :LinearList_SSS_!_TMP_Arguments_!
- Set _TMP_Arguments_=
- Goto :Eof
- ::LinearList_SSS Begin
- :LinearList_SSS_Init ListName MaxLength
- Set /A "%~1.MaxLength=%~2"
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_Clear ListName
- For /L %%a In (1 1 !%~1.MaxLength!) Do (
- Set "%~1.Element[%%a]="
- )
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_Delete ListName
- Call :LinearList_SSS_Clear "%~1"
- Set "%~1.MaxLength="
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_GetElem ListName Index VarToReturn
- Set /A _LinearList_SSS_GetElem_TMP_Index=%~2
- If !_LinearList_SSS_GetElem_TMP_Index! Lss 1 (Set /A ErrorLevel=1 & Goto :Eof)
- If !_LinearList_SSS_GetElem_TMP_Index! Gtr !%~1.MaxLength! (Set /A ErrorLevel=1 & Goto :Eof)
- Call Set "%~3=%%%~1.Element[!_LinearList_SSS_GetElem_TMP_Index!]%%"
- Set _LinearList_SSS_GetElem_TMP_Index=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_EditElem ListName Index VarToReplaceWith
- Set /A _LinearList_SSS_EditElem_TMP_Index=%~2
- If !_LinearList_SSS_EditElem_TMP_Index! Lss 1 (Set /A ErrorLevel=1 & Goto :Eof)
- If !_LinearList_SSS_EditElem_TMP_Index! Gtr !%~1.MaxLength! (Set /A ErrorLevel=1 & Goto :Eof)
- Set "%~1.Element[!_LinearList_SSS_EditElem_TMP_Index!]=!%~3!"
- Set _LinearList_SSS_EditElem_TMP_Index=
- Set /A ErrorLevel=0
- Goto :Eof
- ::LinearList_SSS End
库名:队列
实现:
链式储存结构-单向链表(含头结点)。
(Linked Storage Structure - Singly Linked List)
用法:Call Queue_LSS 函数名 参数
函数:
:Init <QueueName>
建立空的队列。
:Clear <?QueueName?>
清空队列。
:Delete <QueueName>
删除队列。
变量QueueName也会被删除。
:IsEmpty <?QueueName?>
判断队列是否为空。
:Enqueue <?QueueName?> <VarToInsert>
将VarToInsert插入队列。
:Dequeue <?QueueName?> [VarToReturn]
将队头数据元素从队列中删除并返回。
eep <?QueueName?> <VarToReturn>
返回队头元素但不删除。
Stack_LSS.txt复制代码
- ::Code by OldLiu
- ::老刘编写
- ::Start
- Set "_TMP_Arguments_=%*"
- If "!_TMP_Arguments_:~,1!" Equ ":" (
- Set "_TMP_Arguments_=!_TMP_Arguments_:~1!"
- )
- Call :Queue_LSS_!_TMP_Arguments_!
- Set _TMP_Arguments_=
- Goto :Eof
- ::Queue_LSS(require LinearList_LSS_SLL) Begin
- :Queue_LSS_Init QueueName
- Call :LinearList_LSS_SLL_Init "%~1"
- Call :LinearList_LSS_SLL_EditNodeElem "%~1" "%~1"
- Goto :Eof
- :Queue_LSS_Clear QueueName
- Call :LinearList_LSS_SLL_Clear "%~1"
- Set /A _Queue_LSS_Clear_TMP_HeadNodePtr=%~1
- Call :LinearList_LSS_SLL_EditNodeElem "%~1" "_Queue_LSS_Clear_TMP_HeadNodePtr"
- Set _Queue_LSS_Clear_TMP_HeadNodePtr=
- Goto :Eof
- :Queue_LSS_Delete QueueName
- Call :LinearList_LSS_SLL_Delete "%~1"
- Goto :Eof
- :Queue_LSS_IsEmpty QueueName
- Call :LinearList_LSS_SLL_IsEmpty "%~1"
- Goto :Eof
- :Queue_LSS_Enqueue QueueName VarToInsert
- Call :LinearList_LSS_SLL_GetNodeElem "%~1" _Queue_LSS_Enqueue_TMP_QueueRearPtr
- Call :LinearList_LSS_SLL_InsertNextNode _Queue_LSS_Enqueue_TMP_QueueRearPtr "%~2"
- Call :LinearList_LSS_SLL_EditNodeElem "%~1" ErrorLevel
- Goto :Eof
- :Queue_LSS_Dequeue QueueName [VarToReturn]
- Call :LinearList_LSS_SLL_DeleteNextNode "%~1" "%~2"
- If !ErrorLevel! Neq 0 Goto :Eof
- Call :Queue_LSS_IsEmpty "%~1"
- If !ErrorLevel! Equ 0 Call :Queue_LSS_Clear "%~1"
- Set /A ErrorLevel=0
- Goto :Eof
- :Queue_LSS_Peep QueueName VarToReturn
- Call :LinearList_LSS_SLL_GetNextNodePtr "%~1"
- Call :LinearList_LSS_SLL_GetNodeElem ErrorLevel "%~2"
- Goto :Eof
- ::Queue_LSS End
- ::LinearList_LSS_SLL Begin
- :LinearList_LSS_SLL_GetRandom
- Set /A ErrorLevel=%random%%%10000+%random%*10000
- If !ErrorLevel! Equ 0 Goto GetRandom
- If Defined Memory[!ErrorLevel!].Data Goto GetRandom
- Goto :Eof
- :LinearList_LSS_SLL_Init ListName
- Call :LinearList_LSS_SLL_GetRandom
- Set /A %~1=ErrorLevel
- Set Memory[!ErrorLevel!].Data=ListHead
- Set /A Memory[!ErrorLevel!].Next=0
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Clear ListName
- Call :LinearList_LSS_SLL_DeleteNextNode "%~1"
- If !ErrorLevel! Equ 0 Goto :LinearList_LSS_SLL_Clear
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Delete ListName
- Call :LinearList_LSS_SLL_Clear "%~1"
- Set Memory[!%~1!].Data=
- Set Memory[!%~1!].Next=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetLength ListName
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_=0
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=%~1
- :LinearList_LSS_SLL_GetLength_Loop
- Call :LinearList_LSS_SLL_GetNextNodePtr _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=ErrorLevel
- If !_LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_! Neq 0 (
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_+=1
- Goto LinearList_LSS_SLL_GetLength_Loop
- )
- Set /A ErrorLevel=_LinearList_LSS_SLL_GetLength_TMP_ListLength_
- Set _LinearList_LSS_SLL_GetLength_TMP_ListLength_=
- Set _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=
- Goto :Eof
- :LinearList_LSS_SLL_IsEmpty ListName
- :LinearList_LSS_SLL_GetNextNodePtr NodePtr
- Set /A _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=%~1
- Set /A ErrorLevel=Memory[!_LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_!].Next
- Set _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_InsertNextNode NodePtr VarToInsert
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next
- Call :LinearList_LSS_SLL_GetRandom
- Set /A Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next=ErrorLevel
- Set /A Memory[!ErrorLevel!].Next=_LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_
- Set "Memory[!ErrorLevel!].Data=!%~2!"
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_DeleteNextNode NodePtr [VarToSaveNextNodeElemValue]
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next
- If !_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_! Equ 0 (
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Set /A Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next
- If "%~2" Neq "" Call Set "%~2=%%Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data%%"
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next=
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetNodeElem NodePtr VarToSaveElemValue
- Set /A LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=%~1
- Call Set "%~2=%%Memory[!LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_!].Data%%"
- Set LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_EditNodeElem NodePtr VarToReplaceElemValue
- Set /A LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=%~1
- Set "Memory[!LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_!].Data=!%~2!"
- Set LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- ::LinearList_LSS_SLL End
库名:堆栈
实现:
链式储存结构-单向链表(含头结点)。
(Linked Storage Structure - Singly Linked List)
头结点的Next指向栈顶结点。
结点字段:
Data 储存结点的数据。
Next 指向结点对应的下一个结点。
用法:Call Stack_LSS 函数名 参数
函数:
:Init <StackName>
初始化操作,建立一个空的堆栈。
:Clear <?StackName?>
清空堆栈。
:Delete <StackName>
删除堆栈。
:IsEmpty <?StackName?>
判断堆栈是否为空。
:GetLength <?StackName?>
ErrorLevel返回堆栈中的元素个数。
:Push <?StackName?> <VarToPush>
变量入栈。
:Pop <?StackName?> <VarToReturn>
变量出栈。
:GetTopElem <?StackName?> <VarToReturn>
得到栈顶元素。
:EditTopElem <?StackName?> <VarToReplaceWith>
修改栈顶元素。
Stack_SSS.txt复制代码
- ::Code by OldLiu
- ::老刘编写
- ::Start
- Set "_TMP_Arguments_=%*"
- If "!_TMP_Arguments_:~,1!" Equ ":" (
- Set "_TMP_Arguments_=!_TMP_Arguments_:~1!"
- )
- Call :Stack_LSS_!_TMP_Arguments_!
- Set _TMP_Arguments_=
- Goto :Eof
- ::Stack_LSS(require LinearList_LSS_SLL) Begin
- :Stack_LSS_Init StackName
- Call :LinearList_LSS_SLL_Init "%~1"
- Goto :Eof
- :Stack_LSS_Clear StackName
- Call :LinearList_LSS_SLL_Clear "%~1"
- Goto :Eof
- :Stack_LSS_Delete StackName
- Call :LinearList_LSS_SLL_Delete "%~1"
- Goto :Eof
- :Stack_LSS_IsEmpty StackName
- Call :LinearList_LSS_SLL_IsEmpty "%~1"
- Goto :Eof
- :Stack_LSS_GetLength StackName
- Call :LinearList_LSS_SLL_GetLength "%~1"
- Goto :Eof
- :Stack_LSS_Push StackName VarToPush
- Call :LinearList_LSS_SLL_InsertNextNode "%~1" "%~2"
- Set /A ErrorLevel=0
- Goto :Eof
- :Stack_LSS_Pop StackName VarToReturn
- Call :LinearList_LSS_SLL_DeleteNextNode "%~1" "%~2"
- Goto :Eof
- :Stack_LSS_GetTopElem StackName VarToReturn
- Call :LinearList_LSS_SLL_GetNextNodePtr "%~1"
- If !ErrorLevel! Equ 0 (
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Call :LinearList_LSS_SLL_GetNodeElem ErrorLevel "%~2"
- Goto :Eof
- :Stack_LSS_EditTopElem StackName VarToReplaceWith
- Call :LinearList_LSS_SLL_GetNextNodePtr "%~1"
- If !ErrorLevel! Equ 0 (
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Call :LinearList_LSS_SLL_EditNodeElem ErrorLevel "%~2"
- Goto :Eof
- ::Stack_LSS End
- ::LinearList_LSS_SLL Begin
- :LinearList_LSS_SLL_GetRandom
- Set /A ErrorLevel=%random%%%10000+%random%*10000
- If !ErrorLevel! Equ 0 Goto GetRandom
- If Defined Memory[!ErrorLevel!].Data Goto GetRandom
- Goto :Eof
- :LinearList_LSS_SLL_Init ListName
- Call :LinearList_LSS_SLL_GetRandom
- Set /A %~1=ErrorLevel
- Set Memory[!ErrorLevel!].Data=ListHead
- Set /A Memory[!ErrorLevel!].Next=0
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Clear ListName
- Call :LinearList_LSS_SLL_DeleteNextNode "%~1"
- If !ErrorLevel! Equ 0 Goto :LinearList_LSS_SLL_Clear
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_Delete ListName
- Call :LinearList_LSS_SLL_Clear "%~1"
- Set Memory[!%~1!].Data=
- Set Memory[!%~1!].Next=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetLength ListName
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_=0
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=%~1
- :LinearList_LSS_SLL_GetLength_Loop
- Call :LinearList_LSS_SLL_GetNextNodePtr _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_
- Set /A _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=ErrorLevel
- If !_LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_! Neq 0 (
- Set /A _LinearList_LSS_SLL_GetLength_TMP_ListLength_+=1
- Goto LinearList_LSS_SLL_GetLength_Loop
- )
- Set /A ErrorLevel=_LinearList_LSS_SLL_GetLength_TMP_ListLength_
- Set _LinearList_LSS_SLL_GetLength_TMP_ListLength_=
- Set _LinearList_LSS_SLL_GetLength_TMP_Next_Node_Ptr_=
- Goto :Eof
- :LinearList_LSS_SLL_IsEmpty ListName
- :LinearList_LSS_SLL_GetNextNodePtr NodePtr
- Set /A _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=%~1
- Set /A ErrorLevel=Memory[!_LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_!].Next
- Set _LinearList_LSS_SLL_GetNextNodePtr_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_InsertNextNode NodePtr VarToInsert
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next
- Call :LinearList_LSS_SLL_GetRandom
- Set /A Memory[!_LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_!].Next=ErrorLevel
- Set /A Memory[!ErrorLevel!].Next=_LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_
- Set "Memory[!ErrorLevel!].Data=!%~2!"
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NextNodePtr_=
- Set _LinearList_LSS_SLL_InsertNextNode_TMP_NodePtr_=
- Goto :Eof
- :LinearList_LSS_SLL_DeleteNextNode NodePtr [VarToSaveNextNodeElemValue]
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=%~1
- Set /A _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next
- If !_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_! Equ 0 (
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Set /A Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_!].Next=Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next
- If "%~2" Neq "" Call Set "%~2=%%Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data%%"
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Next=
- Set Memory[!_LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_!].Data=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_Next_Node_Ptr_=
- Set _LinearList_LSS_SLL_DeleteNextNode_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_GetNodeElem NodePtr VarToSaveElemValue
- Set /A LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=%~1
- Call Set "%~2=%%Memory[!LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_!].Data%%"
- Set LinearList_LSS_SLL_GetNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_LSS_SLL_EditNodeElem NodePtr VarToReplaceElemValue
- Set /A LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=%~1
- Set "Memory[!LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_!].Data=!%~2!"
- Set LinearList_LSS_SLL_EditNodeElem_TMP_NodePtr_=
- Set /A ErrorLevel=0
- Goto :Eof
- ::LinearList_LSS_SLL End
库名:堆栈
实现:
顺序储存结构
(Sequence Storage Structure)
用法:Call Stack_SSS 函数名 参数
函数:
:Init <StackName> <?MaxLength?>
初始化操作,建立一个空的堆栈。
堆栈最多可储存MaxLength个元素。
:Clear <StackName>
清空堆栈。
:Delete <StackName>
删除堆栈。
:IsEmpty <StackName>
判断堆栈是否为空。
:IsFull <StackName>
判断堆栈是否已满。
:GetLength <StackName>
ErrorLevel返回堆栈中的元素个数。
:Push <StackName> <VarToPush>
变量入栈。
:Pop <StackName> <VarToReturn>
变量出栈。
:GetTopElem <StackName> <VarToReturn>
得到栈顶元素。
:EditTopElem <StackName> <VarToReplaceWith>
修改栈顶元素。
算法实例复制代码
- ::Code by OldLiu
- ::老刘编写
- ::Start
- Set "_TMP_Arguments_=%*"
- If "!_TMP_Arguments_:~,1!" Equ ":" (
- Set "_TMP_Arguments_=!_TMP_Arguments_:~1!"
- )
- Call :Stack_SSS_!_TMP_Arguments_!
- Set _TMP_Arguments_=
- Goto :Eof
- ::Stack_SSS(require LinearList_SSS) Begin
- :Stack_SSS_Init StackName MaxLength
- Call :LinearList_SSS_Init "%~1" "%~2"
- Set /A %~1.StackTop=0
- Goto :Eof
- :Stack_SSS_Clear StackName
- Call :LinearList_SSS_Clear "%~1"
- Set /A %~1.StackTop=0
- Goto :Eof
- :Stack_SSS_Delete StackName
- Call :LinearList_SSS_Delete "%~1"
- Set %~1.StackTop=
- Goto :Eof
- :Stack_SSS_GetLength StackName
- :Stack_SSS_IsEmpty StackName
- Set /A ErrorLevel=%~1.StackTop
- Goto :Eof
- :Stack_SSS_IsFull StackName
- Set /A ErrorLevel=%~1.MaxLength-%~1.StackTop
- Goto :Eof
- :Stack_SSS_Push StackName VarToPush
- Call :Stack_SSS_IsFull "%~1"
- If "!ErrorLevel!" Equ "0" (
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Set /A %~1.StackTop+=1
- Call :Stack_SSS_EditTopElem "%~1" "%~2"
- Set /A ErrorLevel=0
- Goto :Eof
- :Stack_SSS_Pop StackName VarToReturn
- Call :Stack_SSS_IsEmpty "%~1"
- If "!ErrorLevel!" Equ "0" (
- Set /A ErrorLevel=1
- Goto :Eof
- )
- Call :Stack_SSS_GetTopElem "%~1" "%~2"
- Set /A %~1.StackTop-=1
- Set /A ErrorLevel=0
- Goto :Eof
- :Stack_SSS_GetTopElem StackName VarToReturn
- Call :LinearList_SSS_GetElem "%~1" "%~1.StackTop" "%~2"
- Goto :Eof
- :Stack_SSS_EditTopElem StackName VarToReplaceWith
- Call :LinearList_SSS_EditElem "%~1" "%~1.StackTop" "%~2"
- Goto :Eof
- ::Stack_SSS End
- ::LinearList_SSS Begin
- :LinearList_SSS_Init ListName MaxLength
- Set /A "%~1.MaxLength=%~2"
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_Clear ListName
- For /L %%a In (1 1 !%~1.MaxLength!) Do (
- Set "%~1.Element[%%a]="
- )
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_Delete ListName
- Call :LinearList_SSS_Clear "%~1"
- Set "%~1.MaxLength="
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_GetElem ListName Index VarToReturn
- Set /A _LinearList_SSS_GetElem_TMP_Index=%~2
- If !_LinearList_SSS_GetElem_TMP_Index! Lss 1 (Set /A ErrorLevel=1 & Goto :Eof)
- If !_LinearList_SSS_GetElem_TMP_Index! Gtr !%~1.MaxLength! (Set /A ErrorLevel=1 & Goto :Eof)
- Call Set "%~3=%%%~1.Element[!_LinearList_SSS_GetElem_TMP_Index!]%%"
- Set _LinearList_SSS_GetElem_TMP_Index=
- Set /A ErrorLevel=0
- Goto :Eof
- :LinearList_SSS_EditElem ListName Index VarToReplaceWith
- Set /A _LinearList_SSS_EditElem_TMP_Index=%~2
- If !_LinearList_SSS_EditElem_TMP_Index! Lss 1 (Set /A ErrorLevel=1 & Goto :Eof)
- If !_LinearList_SSS_EditElem_TMP_Index! Gtr !%~1.MaxLength! (Set /A ErrorLevel=1 & Goto :Eof)
- Set "%~1.Element[!_LinearList_SSS_EditElem_TMP_Index!]=!%~3!"
- Set _LinearList_SSS_EditElem_TMP_Index=
- Set /A ErrorLevel=0
- Goto :Eof
- ::LinearList_SSS End
复制代码
- @Echo off
- rem 参数:头指针数值
- Set /A _TMP_Ptr_Slow_=_TMP_Ptr_Fast_=%~1,_TMP_Index_=0
- Goto J
- :Loop
- Set /A _TMP_Index_+=1
- Set /A _TMP_Ptr_Slow_=Memory[!_TMP_Ptr_Slow_!].Next
- Set /A _TMP_Ptr_Fast_=Memory[!_TMP_Ptr_Fast_!].Next
- Set /A _TMP_Ptr_Fast_=Memory[!_TMP_Ptr_Fast_!].Next
- :J
- For %%a in (Memory[!_TMP_Ptr_Fast_!].Next) Do (
- If !%%a! Neq 0 (
- Goto Loop
- ) Else (
- Goto Print
- )
- )
- For %%a in (Memory[!_TMP_Ptr_Fast_!].Next) Do (
- For %%b in (Memory[!%%a!].Next) Do (
- If !%%b! Neq 0 (
- Goto Loop
- ) Else (
- Set /A _TMP_Index_+=1
- )
- )
- )
- Echo !_TMP_Index_!
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |