From 9ee91c759c5a87030cebb6b79adc94230f23da4a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 19 Apr 2017 22:43:18 +0800 Subject: remove --- DSAA/chap3_lists_stacks_queues/ex_2.c | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 DSAA/chap3_lists_stacks_queues/ex_2.c (limited to 'DSAA/chap3_lists_stacks_queues/ex_2.c') diff --git a/DSAA/chap3_lists_stacks_queues/ex_2.c b/DSAA/chap3_lists_stacks_queues/ex_2.c new file mode 100644 index 0000000..103fef6 --- /dev/null +++ b/DSAA/chap3_lists_stacks_queues/ex_2.c @@ -0,0 +1,64 @@ +#include +#include + +#include "list.h" + +Position FindNth( List L, int nth ) +{ + int i; + Position P; + P = L; + + for( i = 0; i < nth && P != NULL; i++ ) + { + P = P->Next; + } + + return P; +} + +void PrintLots( List L, List P ) +{ + int i; + Position Posi; + + for( P = P->Next; P != NULL; P = P->Next ) + { + Posi = FindNth( L, P->Element ); + + if (Posi != NULL) + { + printf("%d ", Posi->Element); + } + } + + printf("\n"); +} + +int main() +{ + List L, P; + L = malloc( sizeof( struct Node ) ); + P = malloc( sizeof( struct Node ) ); + + Insert(6, P, P); + Insert(4, P, P); + Insert(3, P, P); + Insert(1, P, P); + + Insert(8, L, L); + Insert(7, L, L); + Insert(6, L, L); + Insert(5, L, L); + Insert(4, L, L); + Insert(3, L, L); + Insert(2, L, L); + Insert(1, L, L); + + PrintList( P ); + PrintList( L ); + + PrintLots( L, P ); + + return 0; +} -- cgit v1.2.3