#include <iostream>
using namespace std;
struct Node
{
int data;
Node* next;
};
class Linklist
{
public:
//初始化
void init()
{
head = new Node;
head->next = NULL;
len = 0;
}
void output()
{
cout << "长度" << len << endl;
if (len>0)
{
cout << "内容:";
Node* p = head->next;
for (int i = 0; i < len; i++)
{
cout << p->data << " ";
p = p->next;
}
cout<<endl;
}
}
//插入
void insert( int n,int value)//此处n为链表的长度
{
Node* p = head;
for (int i = 0; i < n-1; i++)
{
p = p->next;
}
Node* q = new Node;
q->data = value;
q->next = NULL;
//insert
q->next = p->next;
p->next = q;
len++;
}
int Getlen()
{
return len;
}
//删除操作
void Delete (int pos, int*value)//传入要删除的结点内容的地址
{
//Linklist* p = head; linklist
Node* p =
【数据结构】单链表的删除,插入,销毁操作实现
最新推荐文章于 2024-06-07 15:34:45 发布
本文详细介绍了如何使用C++编程语言实现单链表的数据结构,并探讨了单链表中节点的删除、插入以及链表的销毁等核心操作,通过实例代码加以说明,旨在帮助读者深入理解数据结构的基础知识。
摘要由CSDN通过智能技术生成