当前位置: 首页 > 工具软件 > node-abc > 使用案例 >

node * 和 node **的使用

湛宜春
2023-12-01
#include<iostream>
using namespace std;
struct node
{
	node* prev;
	int  value;
	node* next;
};
void reverse2(struct node **head)
{
	struct node *temp = NULL;
	struct node *current = *head;
	cout << "this is the address of my point thinkEEEE " << &(*head) << endl;
	while (current != NULL)
	{
		temp = current->prev;
		current->prev = current->next;
		current->next = temp;
		current = current->prev;
	}
	if (temp != NULL)
		*head = temp->prev;
	cout << "this is the address of my point think@@@@ " << &(*head) << endl;
}
node * reverse1(struct node *head)
{
	struct node *temp = NULL;
	struct node *current = head;
	cout << "this is the address of point my thinkQQQQ " << &head << endl;
	while (current != NULL)
	{
		temp = current->prev;
		current->prev = current->next;
		current->next = temp;
		current = current->prev;
	}
	if (temp != NULL)
		head = temp->prev;
	return head;
}
int main()
{
	/*双向链表1<-->2<-->3*/
	node node1, node2, node3;
	node1.prev = NULL;
	node1.value = 1;
	node2.prev = &node1;
	node2.value = 2;
	node3.prev = &node2;
	node3.value = 3;
	node1.next = &node2;
	node2.next = &node3;
	node3.next = NULL;
	node *head = &node1;

	//head = reverse1(head);
	reverse2(&head);
	cout << "this is the address of my point think##### " << &head << endl;

    cout << "after the reverse ";
	while (head != NULL)
	{
		cout << head->value << "  ";
		head = head->next;
	}
	system("pause");
}
/*
  调用reverse1函数后的结果,可以发现输出的地址是不一样的
  this is the address of point my thinkQQQQ  008FF7CC  
  this is the address of my point think##### 008FF8A0
  after the reverse 3  2  1  请按任意键继续. . .
*/
/*
   调用reverse2函数后的结果,可以发现输出的地址是一样的
   this is the address of my point thinkEEEE  0113FC14
   this is the address of my point think@@@@  0113FC14
   this is the address of my point think##### 0113FC14
   after the reverse 3  2  1  请按任意键继续. . .
*/

 类似资料: