aboutsummaryrefslogtreecommitdiff
path: root/DSAA/chap3_lists_stacks_queues/ex_3.c
diff options
context:
space:
mode:
Diffstat (limited to 'DSAA/chap3_lists_stacks_queues/ex_3.c')
-rw-r--r--DSAA/chap3_lists_stacks_queues/ex_3.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/DSAA/chap3_lists_stacks_queues/ex_3.c b/DSAA/chap3_lists_stacks_queues/ex_3.c
new file mode 100644
index 0000000..6981ce9
--- /dev/null
+++ b/DSAA/chap3_lists_stacks_queues/ex_3.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "list.h"
+
+void SwapSinglyAdjacentNode( Position FrontP, Position BackP , List L)
+{
+ Position TmpCell;
+
+ TmpCell = FindPrevious( FrontP->Element, L );
+ TmpCell->Next = BackP;
+
+ TmpCell = FrontP;
+ FrontP->Next = BackP->Next;
+ BackP->Next = TmpCell;
+}
+
+void SwapDoublyAdjacnetNode( Position P1, Position P2 )
+{
+
+}
+
+int main()
+{
+ List L;
+ Position Front, Back;
+
+ L = malloc( sizeof( struct Node ) );
+
+ Insert(1, L, L);
+ Insert(2, L, L);
+ Insert(3, L, L);
+ Insert(4, L, L);
+
+ PrintList( L );
+
+ Front = Find(3, L);
+ Back = Find(2, L);
+
+ SwapSinglyAdjacentNode(Front, Back, L);
+
+ PrintList( L );
+
+ return 0;
+}