本人设计的链表翻转(单链表),含增删查改全部代码,接口基本复制过去就能用了
如果发现错误欢迎指正!
翻转具体代码在本文最后一个函数中
#include <iostream>
using namespace std;
struct node
{
int data;
struct node* next;
};
void inser_node(struct node *head,int data)
{
struct node *new_node = new struct node;
new_node->data = data;
new_node->next = NULL;
//找到最后一个节点
struct node *pos = head;
while(pos->next != NULL)
{
pos = pos->next;
}
//插入节点
pos->next = new_node;
}
void updata_node(struct node *head,int old_data,int new_data)
{
//1.找到需要修改的数据
struct node *pos = head->next;
while (pos!= NULL)
{
if(pos->data == old_data)
{
pos->data = new_data;
}
pos = pos->next;
}
}
//遍历
void show_list(struct node*head)
{
//指向第一个节点
struct node *pos = head->n