aboutsummaryrefslogtreecommitdiff
path: root/DSAA/chap3_lists_stacks_queues/ex_2.c
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2017-04-19 22:43:18 +0800
committerSteve Lee <me@xiangyangli.com>2017-04-19 22:43:18 +0800
commit9ee91c759c5a87030cebb6b79adc94230f23da4a (patch)
tree4184793354ac57cdbf7002e6821c301bc24ad44a /DSAA/chap3_lists_stacks_queues/ex_2.c
parentce07c94e0ec62a829e0d0c447ec4c932f0f78c3d (diff)
downloadPersonal-9ee91c759c5a87030cebb6b79adc94230f23da4a.tar.xz
Personal-9ee91c759c5a87030cebb6b79adc94230f23da4a.zip
remove
Diffstat (limited to 'DSAA/chap3_lists_stacks_queues/ex_2.c')
-rw-r--r--DSAA/chap3_lists_stacks_queues/ex_2.c64
1 files changed, 64 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+#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;
+}