summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bubblesort
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-02-22 22:20:48 +0000
committerKarl Berry <karl@freefriends.org>2021-02-22 22:20:48 +0000
commit1f8a99f91f89d808a685fb90434693017786a8a6 (patch)
treec0adb02e7b8fd39fc9335d04d8dcd020fb37b570 /Master/texmf-dist/tex/latex/bubblesort
parent4220324e99226b427519e0380034f951f67a011f (diff)
parentd9e54ef03db8d244f5386fc89efffccb3d483a5e (diff)
sync with trunk 57841 to continue testing
git-svn-id: svn://tug.org/texlive/branches/branch2020@57848 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/bubblesort')
-rw-r--r--Master/texmf-dist/tex/latex/bubblesort/bubblesort.sty146
1 files changed, 146 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/bubblesort/bubblesort.sty b/Master/texmf-dist/tex/latex/bubblesort/bubblesort.sty
new file mode 100644
index 00000000000..6f76e682025
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/bubblesort/bubblesort.sty
@@ -0,0 +1,146 @@
+%%
+%% This is file `bubblesort.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% bubblesort.dtx (with options: `package')
+%% This is a generated file. Copyright (C) 2020 by Laurence R Taylor
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%% http://www.latex-project.org/lppl.txt
+%% and version 1.3c or later is part of all distributions of
+%% LaTeX version 2005/12/01 or later.
+\NeedsTeXFormat{LaTeX2e}[2005/12/01]
+\ProvidesPackage{bubblesort}
+ [2020/07/01 v1.0 implements a bubble sort]
+
+\RequirePackage{etoolbox}
+
+\makeatletter
+
+\newcount\bubblesortflag
+\newbool{did a flip}
+\def\@bubblesort@EoS{}% End-of-Stack indicator
+
+\def\realSort#1#2{%
+\ifdimless{#2 pt}{#1 pt}{\bubblesortflag=1}{\bubblesortflag=-1}}
+\def\alphSort#1#2{\ifnumequal{\pdfstrcmp{#1}{#2}}{1}%
+{\bubblesortflag=1}{\bubblesortflag=-1}}
+\newcommand{\bubblesort}[3][\realSort]{%
+%% #1 comparator macro, #2 input stack/list, #3 answer list: #2=#3 OK
+\def\@bubblesort@rightList{}%
+\expandafter\@bubblesort@shiftOne#2{}{}{}\@bubblesort@EoS{%
+\@bubblesort@testItem}{\@bubblesort@workingList}%
+\expandafter\@bubblesort@S{#3}{#1}%
+}
+\def\@bubblesort@S#1#2{% #1 is name for answer --- #2 is comparator macro
+\boolfalse{did a flip}\def\@bubblesort@leftList{}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingList{}{}\@bubblesort@EoS{%
+\@bubblesort@nextItem}{\@bubblesort@workingList}%
+\whileboolexpr{not test{\ifdefvoid{\@bubblesort@nextItem}}}{%
+#2{\@bubblesort@testItem}{\@bubblesort@nextItem}\relax%
+\ifnumequal{\bubblesortflag}{1}{% flip
+\booltrue{did a flip}%
+\expandafter\@bubblesort@rightappendItem\expandafter{\@bubblesort@nextItem}%
+\to\@bubblesort@leftList%
+}{%
+\expandafter\@bubblesort@rightappendItem\expandafter{\@bubblesort@testItem}%
+\to\@bubblesort@leftList%
+\expandafter\def\expandafter\@bubblesort@testItem\expandafter{\@bubblesort@nextItem}%
+}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingList\@bubblesort@EoS{%
+\@bubblesort@nextItem}{\@bubblesort@workingList}%
+}%
+\expandafter\leftappendItem\expandafter{\@bubblesort@testItem}\to\@bubblesort@rightList%
+\ifbool{did a flip}{%
+\expandafter\def\expandafter\@bubblesort@workingList\expandafter%
+{\@bubblesort@leftList{}{}{}}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingList\@bubblesort@EoS{%
+\@bubblesort@testItem}{\@bubblesort@workingList}%
+\def\@bubblesort@leftList{}%
+\@bubblesort@S{#1}{#2}}%
+{\@bubblesort@output{#1}{\@bubblesort@leftList\@bubblesort@rightList}%
+}}
+\def\@bubblesort@output#1#2{% #1 name of output list or empty --- #2 sorted stack
+\ifstrempty{#1}%
+{#2}{\expandafter\edef\expandafter#1\expandafter{#2}}%
+}
+\newcommand{\doublebubblesort}[5][\realSort]{%
+%% #1 comparator macro
+%% #2 input stack/list --- #3 output for #2 stack/list; #2=#3 OK
+%% #4 second stack/list --- #5 answer list for #4; #4=#5 OK
+\def\@bubblesort@rightListA{}\def\@bubblesort@rightListB{}%
+\expandafter\@bubblesort@shiftOne#2{}{}{}\@bubblesort@EoS{%
+\@bubblesort@testItemA}{\@bubblesort@workingListA}%
+\expandafter\@bubblesort@shiftOne#4{}{}{}\@bubblesort@EoS{%
+\@bubblesort@testItemB}{\@bubblesort@workingListB}%
+\expandafter\@doublebubblesort@S{#3}{#5}{#1}%
+}
+\def\@doublebubblesort@S#1#2#3{%
+%% #1 output for sorted stack/list --- #2 output for ``sorted'' stack/list
+%% #3 comparator macro
+\boolfalse{did a flip}\def\@bubblesort@leftListA{}\def\@bubblesort@leftListB{}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListA{}{}%
+\@bubblesort@EoS{\@bubblesort@nextItemA}{\@bubblesort@workingListA}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListB{}{}%
+\@bubblesort@EoS{\@bubblesort@nextItemB}{\@bubblesort@workingListB}%
+\whileboolexpr{not test{\ifdefvoid{\@bubblesort@nextItemA}}}{%
+#3{\@bubblesort@testItemA}{\@bubblesort@nextItemA}\relax%
+\ifnumequal{\bubblesortflag}{1}{% flip
+\booltrue{did a flip}%
+\expandafter\@bubblesort@rightappendItem\expandafter{%
+\@bubblesort@nextItemA}\to\@bubblesort@leftListA%
+\expandafter\@bubblesort@rightappendItem\expandafter{%
+\@bubblesort@nextItemB}\to\@bubblesort@leftListB%
+}{%
+\expandafter\@bubblesort@rightappendItem\expandafter{%
+\@bubblesort@testItemA}\to\@bubblesort@leftListA%
+\expandafter\@bubblesort@rightappendItem\expandafter{%
+\@bubblesort@testItemB}\to\@bubblesort@leftListB%
+\expandafter\def\expandafter\@bubblesort@testItemA\expandafter{%
+\@bubblesort@nextItemA}%
+\expandafter\def\expandafter\@bubblesort@testItemB\expandafter{%
+\@bubblesort@nextItemB}%
+}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListA\@bubblesort@EoS{%
+\@bubblesort@nextItemA}{\@bubblesort@workingListA}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListB\@bubblesort@EoS{%
+\@bubblesort@nextItemB}{\@bubblesort@workingListB}%
+}%
+\expandafter\leftappendItem\expandafter{\@bubblesort@testItemA}\to%
+\@bubblesort@rightListA%
+\expandafter\leftappendItem\expandafter{\@bubblesort@testItemB}\to%
+\@bubblesort@rightListB%
+\ifbool{did a flip}{%
+\expandafter\def\expandafter\@bubblesort@workingListA\expandafter{%
+\@bubblesort@leftListA{}{}{}}%
+\expandafter\def\expandafter\@bubblesort@workingListB\expandafter{%
+\@bubblesort@leftListB{}{}{}}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListA\@bubblesort@EoS{%
+\@bubblesort@testItemA}{\@bubblesort@workingListA}%
+\expandafter\@bubblesort@shiftOne\@bubblesort@workingListB\@bubblesort@EoS{%
+\@bubblesort@testItemB}{\@bubblesort@workingListB}%
+\def\@bubblesort@leftListA{}%
+\def\@bubblesort@leftListB{}%
+\expandafter\@doublebubblesort@S{#1}{#2}{#3}}%
+{\@bubblesort@output{#1}{\@bubblesort@leftListA\@bubblesort@rightListA}%
+\@bubblesort@output{#2}{\@bubblesort@leftListB\@bubblesort@rightListB}}%
+}
+
+\def\@bubblesort@shiftOne#1#2\@bubblesort@EoS#3#4{%
+\expandafter\gdef\expandafter#3\expandafter{#1}%
+\expandafter\gdef\expandafter#4\expandafter{#2}%
+}
+
+\newtoks\ta\newtoks\tb
+\long\def\@bubblesort@rightappendItem#1\to#2{\ta={{#1}}\tb=\expandafter{#2}%
+\edef#2{\the\tb\the\ta}}
+\long\def\leftappendItem#1\to#2{\ta={{#1}}\tb=\expandafter{#2}%
+\edef#2{\the\ta\the\tb}}
+\makeatother
+\endinput
+%%
+%% End of file `bubblesort.sty'.