用c++语言实现的单链表基本操作,包括单链表的创建(包括头插法和尾插法建表)、结点的查找、删除、排序、打印输出、逆置、链表销毁等基本操作。
IDE:vs2013
具体实现代码如下:
#include "stdafx.h"
#include <malloc.h>
#include <iostream>
using namespace std;
typedef struct Lnode
{
int data;
struct Lnode *next;
}*node;
node head_creat() //头插法建立单链表
{
node head = (struct Lnode *)malloc(sizeof(struct Lnode));
head->next = NULL;
node p;
int temp;
while (cin >> temp)
{
p = (node)malloc(sizeof(struct Lnode));
p->data = temp;
p->next = head->next;
head->next=p;
}
return head;
}
bool search(node h, int target) //查找某元素是否在链表中
{
int flag = 0;
node p = h->