#include<iostream>
using namespace std;
typedef struct List_Node
{
int data;
struct List_Node *next;
} node, *node_pointer;
node *creat( int num )
{
node_pointer p;
p = new node;
p -> data = num;
p -> next = NULL;
return p;
}
int length( node *head )
{
int n = 0;
node *p;
p = head;
while ( p != NULL )
{
n++;
p = p ->next;
}
return n;
}
void print( node *head ,const char *print_str="List As Follows:\n")
{
node *p;
int i = 0;
int n = length(head);
p = head;
if ( p == NULL )
{
cout<<"the list is empty! \n";
}
else
{
cout<<print_str;
for ( i = 1; i <=n; i++)//有头结点
{
cout<<"the "<<i<<" record is: "<<p->data<<"\n";
if ( i != n)
{
p = p -> next;
}
}
}
}
void insert( node_pointer &head, int num )
{
node_pointer
C++实现单链表的创建、插入、删除、逆置操作
最新推荐文章于 2020-10-29 18:27:52 发布
这篇博客介绍了如何使用C++实现单链表的创建、插入元素、删除指定元素以及链表的逆置操作。通过示例代码详细展示了每个操作的过程,并给出了程序运行结果。
摘要由CSDN通过智能技术生成