链表逆序C++版

对于数据结构和算法总是看了理解了会了隔一段时间又忘了又不会了只能作一下记录 /笑哭 会一点写一点吧
//创建链表中的节点结构体
typedef struct node
{	char name[20]; //数据域

	struct node* next; //指针域
}Student;

//尾部添加
Student*  addElement(Student* head,Student* stu){
	Student* per = head;
	while(per->next == NULL){
		per = per->next;
	}
	per->next = stu;
	stu->next = NULL;


	return head;
}

//链表逆序
Student* reverseLink(Student* head){
	Student *per = NULL,*next = NULL;

	while(head){
		next = head->next;
		head->next = per;
		per = head;
		head = next;
	}
	return per;
}

平时还得多看看这些*玩意儿呢

猜你喜欢

转载自blog.csdn.net/ding_westbrook/article/details/80822014
今日推荐