#include <stdio.h>
#include <stdlib.h>
typedef struct Test_tag
{
int num;
struct Test_tag *next;
} Test;
int main(void)
{
Test *head = malloc(sizeof(Test));
Test *n1 = malloc(sizeof(Test));
Test *n2 = malloc(sizeof(Test));
Test *n3 = malloc(sizeof(Test));
head->num = 0;
head->next = n1;
n1->num = 1;
n1->next = n2;
n2->num = 2;
n2->next = n3;
n3->num = 3;
n3->next = NULL;
printf("head: : 0x%.8X\n", (unsigned int)head);
printf("head->num : 0x%.8X\n", (unsigned int)head->num);
printf("head->next : 0x%.8X\n", (unsigned int)head->next);
printf("n1 : 0x%.8X\n", (unsigned int)n1);
printf("n1->num : 0x%.8X\n", (unsigned int)n1->num);
printf("n1->next : 0x%.8X\n", (unsigned int)n1->next);
printf("n2 : 0x%.8X\n", (unsigned int)n2);
printf("n2->num : 0x%.8X\n", (unsigned int)n2->num);
printf("n2->next : 0x%.8X\n", (unsigned int)n2->next);
printf("n3 : 0x%.8X\n", (unsigned int)n3);
printf("n3->num : 0x%.8X\n", (unsigned int)n3->num);
printf("n3->next : 0x%.8X\n", (unsigned int)n3->next);
Test *p;
Test *temp;
p = head;
while(p != NULL)
{
printf("%d ", p->num);
p = p->next;
}
printf("\n");
#if 1
// 删除 n2
p = n1;
temp = p->next;
p->next = temp->next;
free(temp);
#else
// 删除 n2
p = n1;
temp = p->next;
p = temp->next;
free(temp);
#endif
printf("head: : 0x%.8X\n", (unsigned int)head);
printf("head->num : 0x%.8X\n", (unsigned int)head->num);
printf("head->next : 0x%.8X\n", (unsigned int)head->next);
printf("n1 : 0x%.8X\n", (unsigned int)n1);
printf("n1->num : 0x%.8X\n", (unsigned int)n1->num);
printf("n1->next : 0x%.8X\n", (unsigned int)n1->next);
printf("n2 : 0x%.8X\n", (unsigned int)n2);
printf("n2->num : 0x%.8X\n", (unsigned int)n2->num);
printf("n2->next : 0x%.8X\n", (unsigned int)n2->next);
printf("n3 : 0x%.8X\n", (unsigned int)n3);
printf("n3->num : 0x%.8X\n", (unsigned int)n3->num);
printf("n3->next : 0x%.8X\n", (unsigned int)n3->next);
p = head;
while(p != NULL)
{
printf("%d ", p->num);
p = p->next;
}
printf("\n");
return 0;
}
#if 1head: : 0x004861E0
head->num : 0x00000000
head->next : 0x00486218
n1 : 0x00486218
n1->num : 0x00000001
n1->next : 0x00486080
n2 : 0x00486080
n2->num : 0x00000002
n2->next : 0x004860B8
n3 : 0x004860B8
n3->num : 0x00000003
n3->next : 0x00000000
0 1 2 3
head: : 0x004861E0
head->num : 0x00000000
head->next : 0x00486218
n1 : 0x00486218
n1->num : 0x00000001
n1->next : 0x004860B8
n2 : 0x00486080
n2->num : 0xDDDDDDDD
n2->next : 0xDDDDDDDD
n3 : 0x004860B8
n3->num : 0x00000003
n3->next : 0x00000000
0 1 3
请按任意键继续. . .
#if 0head: : 0x010061E0
head->num : 0x00000000
head->next : 0x01006218
n1 : 0x01006218
n1->num : 0x00000001
n1->next : 0x01006080
n2 : 0x01006080
n2->num : 0x00000002
n2->next : 0x010060B8
n3 : 0x010060B8
n3->num : 0x00000003
n3->next : 0x00000000
0 1 2 3
head: : 0x010061E0
head->num : 0x00000000
head->next : 0x01006218
n1 : 0x01006218
n1->num : 0x00000001
n1->next : 0x01006080
n2 : 0x01006080
n2->num : 0xDDDDDDDD
n2->next : 0xDDDDDDDD
n3 : 0x010060B8
n3->num : 0x00000003
n3->next : 0x00000000
0 1 -572662307 请按任意键继续. . .
|