-
Notifications
You must be signed in to change notification settings - Fork 970
Add LL_REVERSE/DL_REVERSE/CDL_REVERSE macros to utlist
#278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+274
−1
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cc91c8b
utlist: add LL_REVERSE / DL_REVERSE macros for list reversal
xunicatt 4f77edd
tests: updated test101
xunicatt b4f7955
fix: build issue
xunicatt fb59cbe
fix: switched to UTLIST_CASTASGN to build realted issues
xunicatt 6bf2677
fix: do-while loop alignment
xunicatt bd11909
added: / and new test; switched to FOREACH_SAFE loops for freeing up…
xunicatt 0dab673
update docs to add /
xunicatt fd4d67b
fixed formatting
xunicatt 9a739f5
update docs
xunicatt d5bf1d9
utlist: remove unnecessary 'if (head)' check in LL_REVERSE2
xunicatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 0 | ||
| 1 | ||
| 2 | ||
| 4 | ||
| 8 | ||
| 16 | ||
| 32 | ||
| 64 | ||
| 128 | ||
| 256 | ||
| 512 | ||
| 1024 | ||
| 2048 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "utlist.h" | ||
|
|
||
| typedef struct List { | ||
| int value; | ||
| struct List *next; | ||
| } List; | ||
|
|
||
| int main(void) { | ||
| List *list = NULL, *node, *tmp; | ||
| int i; | ||
|
|
||
| for(i = 1; i <= 1024; i <<= 1) { | ||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = i; | ||
| LL_PREPEND(list, node); | ||
| } | ||
|
|
||
| LL_REVERSE(list); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 0; | ||
| LL_PREPEND(list, node); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 2048; | ||
| LL_APPEND(list, node); | ||
|
|
||
| LL_FOREACH(list, node) { | ||
| printf("%d\n", node->value); | ||
| } | ||
|
|
||
| LL_FOREACH_SAFE(list, node, tmp) { | ||
| LL_DELETE(list, node); | ||
| free(node); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 2048 | ||
| 1024 | ||
| 512 | ||
| 256 | ||
| 128 | ||
| 64 | ||
| 32 | ||
| 16 | ||
| 8 | ||
| 4 | ||
| 2 | ||
| 1 | ||
| 0 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "utlist.h" | ||
|
|
||
| typedef struct List { | ||
| int value; | ||
| struct List *prev; | ||
| struct List *next; | ||
| } List; | ||
|
|
||
| int main(void) { | ||
| List *list = NULL, *node, *tmp; | ||
| int i; | ||
|
|
||
| for(i = 1; i <= 1024; i <<= 1) { | ||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = i; | ||
| DL_APPEND(list, node); | ||
| } | ||
|
|
||
| DL_REVERSE(list); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 0; | ||
| DL_APPEND(list, node); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 2048; | ||
| DL_PREPEND(list, node); | ||
|
|
||
| DL_FOREACH(list, node) { | ||
| printf("%d\n", node->value); | ||
| } | ||
|
|
||
| DL_FOREACH_SAFE(list, node, tmp) { | ||
| LL_DELETE(list, node); | ||
| free(node); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 2048 | ||
| 1024 | ||
| 512 | ||
| 256 | ||
| 128 | ||
| 64 | ||
| 32 | ||
| 16 | ||
| 8 | ||
| 4 | ||
| 2 | ||
| 1 | ||
| 0 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "utlist.h" | ||
|
|
||
| typedef struct List { | ||
| int value; | ||
| struct List *prev; | ||
| struct List *next; | ||
| } List; | ||
|
|
||
| int main(void) { | ||
| List *list = NULL, *node, | ||
| *tmp1, *tmp2; | ||
| int i; | ||
|
|
||
| for(i = 1; i <= 1024; i <<= 1) { | ||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = i; | ||
| CDL_APPEND(list, node); | ||
| } | ||
|
|
||
| CDL_REVERSE(list); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 0; | ||
| CDL_APPEND(list, node); | ||
|
|
||
| node = (List*)malloc(sizeof(*node)); | ||
| node->value = 2048; | ||
| CDL_PREPEND(list, node); | ||
|
|
||
| CDL_FOREACH(list, node) { | ||
| printf("%d\n", node->value); | ||
| } | ||
|
|
||
| CDL_FOREACH_SAFE(list, node, tmp1, tmp2) { | ||
| CDL_DELETE(list, node); | ||
| free(node); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.