#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 previous, current, p;
current = head;
previous = NULL;
while ( current != NULL && current -> data < num )
C++实现单链表的创建、插入、删除、逆置操作
最新推荐文章于 2022-08-31 15:03:58 发布