KTUG마당은 KTUG를 방문하는 모든 이용자가 대화를 나누고 소식을 전하는 곳입니다.

  • 로그인 없이 자유롭게 글을 읽고 쓸 수 있는 철학은 처음과 같이 계속됩니다.
  • Team Blog의 글을 이곳 게시판의 "정보글"로 모았습니다. Team blog는 기고자가 올린 글에 질문을 받는 부담을 줄이기 위하여 댓글을 허용하지 않았습니다. 그러나 이곳 게시판으로 모으면서 댓글을 달 수 있습니다. 게시물을 작성하실 때 댓글을 원하지 않으시면 댓글을 허용하시지 않으시기를 바랍니다. 또한 불필요한 소모성 댓글을 달지 않도록 주의하여 주시기를 바랍니다.
  • TeX과 관련된 질문이나 답변은 QnA 마당을 이용하십시오. TeX과 관련된 질문은 지웁니다
  • MathJax를 이용한 수식조판을 사용하실 수 있습니다. 여기를 참조하세요.
  • 스팸 글을 막기 위하여 짧은 시간 내에 다시 글이 등록되는 IP를 막거나, 광고 글을 막기 위하여 금지어로 .com, .net 등을 설정하고 있습니다. 다소간의 불편함이 있으시더라도 양해 바랍니다.
    • 금지어에서 stackexchange, stackoverflow, ctan, overleaf, , github, google.com, gmail.com, .org, .io, sil.org, wiki.com, tistory.com등은 해제하였습니다.
  • 사용하는 편집기는 CKeditor입니다. 편집기에서 [enter]를 누르면 <p> 태그가 들어가고, 문단으로 생각하고 한줄을 비웁니다. 글줄만 바꾸려면 shift-enter 를 누르시면 <BR>가 들어가므로 용도에 맞게 나누어 쓸 수 있습니다.

정보글 문자열의 삽입정렬

2012.10.08 16:51

karnes 조회 수:5152 추천:1

문자열 정렬에 대해서는 DohyunKim 님의 http://www.ktug.or.kr/xe/index.php?document_srl=33728 이 있다.

다음 소스는 xfor 패키지에서 가져온 것으로 원래 숫자에 대해서만 삽입정렬하게 한 것인데 윗글의 \pdfstrcmp를 이용하여 문자열 정렬을 시도해보았다.

정렬 방식은 삽입정렬(insertion sort)


\documentclass{oblivoir}


\usepackage{xfor}


\makeatletter

\newcommand{\insertinto}[2]{%

\def\nlst{}% new list initially empty

\@for\n:=#2\do{%

% store new list in \toks@

\expandafter\toks@\expandafter{\nlst}%

% test current value against new value

%%%\ifnum\n>#1\relax %%%

\ifnum\pdfstrcmp{\n}{#1}=1\relax

% new value needs to be inserted before current value

\edef\newstuff{#1,\n}%

% end for loop at the end of this iteration

\@endfortrue

\else

\edef\newstuff{\n}%

\fi

% append new stuff to new list

\ifx\nlst\@empty

\edef\nlst{\newstuff}%

\else

\edef\nlst{\the\toks@,\newstuff}%

\fi

}%

% check to see if for loop was prematurely terminated

\if@endfor

% loop may have been terminated during final iteration, in

% which case \@forremainder is empty.

\ifx\@forremainder\@empty

% do nothing

\else

% loop prematurely ended, append remainder of original list

% to new list

\expandafter\toks@\expandafter{\nlst}%

\edef\nlst{\the\toks@,\@forremainder}%

\fi

\else

% wasn't prematurely terminated, so new value hasn't been added

% so add now.

\expandafter\toks@\expandafter{\nlst}%

\ifx\nlst\@empty

\edef\nlst{#1}%

\else

\edef\nlst{\the\toks@,#1}%

\fi

\fi

\global\let#2=\nlst

}


\newcommand*{\insertionsort}[1]{%

\def\sortedlist{}%

\@for\val:=#1\do{{\insertinto{\val}{\sortedlist}}}%

\let#1=\sortedlist

}


\makeatother


\begin{document}


\def\chlist{받,은,편,지,함,의,메,일,을,모,두,읽,으,셨,습,니,다}

\insertionsort{\chlist}

\chlist


\def\chlist{{독도는},{우리},{땅이다},{민족},{국가},{자유}}

\insertionsort{\chlist}

\chlist


\end{document}


결과:

outtag.PNG


번호 제목 글쓴이 날짜 조회 수
1130 예전 샘플 문서 갱신: 금강경 newfile noname 2024.05.15 1
1129 xelatex에서 fallbackhanja를 사용할 경우 2024-05 초순경 update후 확인하여 보셔야 할 것 new likesam 2024.05.15 1
1128 daft text [1] file noname 2024.04.29 73
1127 텍으로 작성된 인문사회계 논문 [1] 판돌이 2024.05.05 92
1126 La TeX 라텍 작성 하실 분 구합니다. [2] LaTex 2024.05.04 104
1125 [Lilypond] W. A. Mozart, Laudate Dominum [3] file noname 2024.04.07 108
1124 색인에서 연속하는 페이지 번호 [3] file yihoze 2023.11.16 132
1123 simplebnf v1.0.0: Backus-Naur form (BNF) 문법을 간단히 표시해주는 패키지 [2] file Zeta 2023.11.24 134
1122 [취미] 심심할 때는 괘를 뽑아보세요 [1] file noname 2024.04.16 149
1121 [유틸리티] latexindent [1] noname 2024.03.30 150
1120 Codehigh 패키지 [7] Zeta 2023.11.23 161
1119 게임 테이블 그리기 2 file ischo 2024.02.14 161
1118 [KTUG 문고] 염상섭, 만세전 [13] file noname 2024.05.02 164
1117 잊을 만하면 다시 돌아오는 로또 [4] file yihoze 2023.12.05 182
1116 영어로 작성된 텍 파일의 철자 검사하기 [2] file yihoze 2023.11.03 183
1115 올해 학술대회는 혹시 언제일까요 [2] 크사인 2024.01.09 200
1114 [잡담] 이과가 사랑에 빠졌기에... [6] file noname 2024.04.09 202
1113 표 그리기: Tabular 환경의 표를 tabularray로 그려보자 [2] file noname 2023.11.30 203
1112 님의침묵 file noname 2023.03.01 205
1111 local.conf와 fc-list [4] yihoze 2024.03.28 211



XE Login