Do not use auxiliary nodes, use

xiaoxiao2021-03-06  83

Due to the use of macros, there is still a temporary variable and pointer to introduce several int types, and there is no speed of the XOR operation, and the block assembly is implemented. Just replaced three, the test is the same as the result of C. Speed ​​and space should have improved. #include #include

#define swap (a, b) {/ a = a ^ 0xffffff; / b = b ^ a; / a = a ^ b; / b = b ^ 0xfffffffff; / b = b ^ a; /} #define swap_point ( PA, PB) {/ INT H, T; / PLINKLIST pH, PT; / H = (int) pa; / t = (int) Pb; / pH = (plinklist) h; / pt = (plinklist) T; / SWAP (h, t); / pa = (plinklist) h; / pb = (plinklist) t; /}

Typedef struct taglinklist {int data; struct taglinklist * next; linklist, * plinklist;

INT Main (int Argc, char * argv []) {/ * int a = 10, b = 99; _ASM {MOV EAX, A MOV EBX, B XOR EBX, EAX XOR EAX, EBX XOR EBX, EAX MOV A, EAX MOV B, EBX} Printf ("A =% D, B =% D / N", A, B); * /

INT Count, I; Plinklist head, TmpNode, Tail; Head = null; // Construct LinkList. Printf ("Enter Count:"); scanf ("% d", & count); if (count <= 1) {Printf (PRINTF (COUNT <= 1) {printf "Count Error, Must Large Than 1./N"); exit (1);} for (i = 1; i <= count; i) {tmpnode = (linklist *) malloc (sizeof (linklist)); TmpNode-> DATA = I; Printf ("NO. =% D / T Address:% x, DATA:% D / N", I, TmpNode, Tmpnode-> Data); if (! HEAD) Tail = head = tmpnode Else {tail-> next = tmpnode; tail = tmpnode;}} tail-> next = null; // reverse linelist. If (2 == count) {// n = 2 // swap_point (head, tail-> NEXT); _ASM {MOV EAX, DWORD PTR Head Mov ESI, DWORD PTR Tail Mov ESI, 4 MOV EBX, [EDX] [ESI] xor EBX, EAX XOR EAX, EBX XOR EBX, EAX MOV Head, EAX MOV [EDX] [ESI], EBX} swap_point (head, tail); swap_point (head-> next-> next, tail);} else if (3 == count) {// n = 3 swap_point (Head-> Next, Tail- > next); swap_point (head, tail); swap_point (head-> next-> next, tail);} else {// n> = 4 swap_point (head-> next, tail-> next); swap_point (Head, Tail); swap_point (Head-> Next-> N EXT, TAIL); swap_point (head-> next, tail-> next); swap_point (head-> next-> next, tail); for (i = 6; i <= count; i) {// swap_point (Head-> next, tail); _ASM {Mov Edx, DWORD PTR Head Mov EBX, DWORD PTR Tail Mov ESI, 4 MOV EAX, [EDX] [ESI] xor EBX, EBX, EBX, EBX MOV TAIL , EBX MOV [EDX] [ESI], EAX} // swap_point (Head-> Next-> Next, Tail);

_ASM {MOV EAX, DWORD PTR Head Mov EBX, DWORD PTR Tail Mov ESI, 4 MOV EDX, [EDX] [ESI] MOV EAX, [EDX] [ESI] XOR EBX, EAX XOR EAX, EBX XOR EBX, EAX MOV TAIL , EBX MOV [EDX] [ESI], EAX}}} // Output Reverse LinkList. TmpNode = Head; Printf ("After Reverse./N"); for (i = 1; i <= count; i) {Printf ("NO. =% D / T Address:% x, DATA:% D / N", I, TMPNODE, TMPNODE-> DATA); TMPNODE = TmpNode-> Next; }printf ("tail-> data = % D / N ", TAIL-> DATA); // Release LinkList Printf (" Release LinkList./N "); for (i = 1; i <= count; i) {tmpnode = head; Head = head -> next; free (tmpnode);} return 0;}

转载请注明原文地址:https://www.9cbs.com/read-95515.html

New Post(0)