1.单链表(有头结点,无头节点)
2.插入
不带头结点的处理起来会麻烦一些。
3.删除
4.查找
5.建立链表
6.头插法可以用来实现链表的逆置
代码:
#include<iostream> using namespace std; const int N = 10; typedef struct LNode { int data; LNode* next; }LNode,*LinkList; LinkList TailInsert(LinkList& L)//尾插 { int x; L = (LinkList)malloc(sizeof(LNode)); LNode* p, *s=L; cin >> x; while (x <= 9999) { s = (LNode*)malloc(sizeof(LNode)); s->data = x; p->next = s; p = s; cin >> x; } p->next = NULL; return L; } LinkList HeadInsert(LinkList&L)//头插 { int x; LNode* p, * s = L; L = (LinkList)malloc(sizeof(LNode)); cin >> x; while (x <= 9999) { s = (LNode*)malloc(sizeof(LNode)); s->data = x; s->next = p->next; p->next = s; cin >> x; } return L; } LinkList CheckByData(LinkList L, int e)//按值查找 { LNode* p = L->next; while (p->data != e&&p!=NULL) { p = p->next; } return p; } LinkList CheckByIndex(LinkList L, int index)//按位查找 { LNode* p = L; for (int i = 0; i < index; i++) { p = p->next; } return p; } void del(LNode* p)//删除p结点 { LNode* q = p->next; p->data = q->data; p->next = q->next; free(q); } void ForHeadInsert(LNode* p, int e)//在p结点的前面插入数据为e的结点 { LNode* s = (LNode*)malloc(sizeof(LNode)); s->next = p->next; p->next = s; s->data = p->data; p->data = e; } int main() { LinkList L; //。。。 return 0; }
数据结构.单链表
最新推荐文章于 2024-07-23 18:51:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)