Created
December 30, 2013 18:03
-
-
Save YuukiARIA/8185507 to your computer and use it in GitHub Desktop.
循環リスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
環状リストです。 | |
+----+ | |
| | | |
[0] | | |
| | | |
[1] | | |
| | | |
[2] | | |
| | | |
[3] | | |
| | | |
+----+ | |
最初、ptrは先頭[0]を指しています。 | |
root = ptr で、root も先頭を指すようにしておきます。 | |
+----+ | |
| | | |
root,ptr -->[0] | | |
| | | |
[1] | | |
| | | |
[2] | | |
| | | |
[3] | | |
| | | |
+----+ | |
ptr = ptr->next で次に動きます。 | |
+----+ | |
| | | |
root -->[0] | | |
| | | |
ptr -->[1] | | |
| | | |
[2] | | |
| | | |
[3] | | |
| | | |
+----+ | |
[3]まで来ました。 | |
[3]の次は[0]です。 | |
+----+ | |
| | | |
root -->[0] | | |
| | | |
[1] | | |
| | | |
[2] | | |
| | | |
ptr -->[3] | ptr->next == root | |
| | | |
+----+ | |
ptr = ptr->next の結果、ptr は root に等しくなります。 | |
これによって一周したことが分かります。 | |
+----+ | |
| | | |
root,ptr -->[0] | | |
| | | |
[1] | | |
| | | |
[2] | | |
| | | |
[3] | | |
| | | |
+----+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment