#include<iostream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
using namespace std;
typedef struct student
{
int data;
struct student *next;
}node;
//建立单链表,头插入法;
node *creatlist()
{
node *head, *p, *s;
int x;
//申请新的存储空间,创立头节点;
head = (node*)malloc(sizeof(node));
head->next=NULL; //重要 指针需要初始化;
s = head->next;
cout << "用头插法建立单链表, 请输入链表数据, 以 ctrl+z 结束" << endl;
while ( cin>>x)
{
p = (node*)malloc(sizeof(node));
p->data = x;
head->next = p;
p->next = s;
s = p;
}
return(head);
}
2. 单链表中节点的查找操作
//查找给定的值;
node *locate(node *head, int x)
{
node *p;
p = head->next;
while (p != NULL && p->data != x)
{
p=p->next;
}
if (p == NULL)
cout << "链表中不存在这个数" << endl;
return (p);
}
3. 单链表上的插入操作