博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C语言单链表实现
阅读量:4070 次
发布时间:2019-05-25

本文共 1577 字,大约阅读时间需要 5 分钟。

来源:https://www.bilibili.com/video/BV1Rb411F738?from=search&seid=2404768265956671653

讲的还可以,但是拿ps画图让我感觉有点难受,哈哈,代码风格很棒!值得学习!

#include
#include
struct Node {
int data; struct Node* next;};//创建链表 struct Node * createList(){
struct Node* headNode = (struct Node*)malloc(sizeof(struct Node)); //headNode成为了结构体变量,变量使用前必须被初始化,headNode->data = 1; headNode->next = NULL; return headNode;}//创建结点struct Node * createNode(int data){
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = NULL; return newNode;}//打印结点void printList(struct Node* headNode){
struct Node* pMove = headNode->next; while (pMove) {
printf("%d\t", pMove->data); pMove = pMove->next; } printf("\n");}//插入结点void insertNodeByHead(struct Node* headNode, int data){
struct Node* newNode = createNode(data); newNode->next = headNode->next; headNode->next = newNode;}//删除结点void deleteNodeByAppoin(struct Node* headNode, int posData){
struct Node* posNode = headNode->next; struct Node* posNodeFront = headNode; if (posNode == NULL) {
printf("无法删除空链表\n"); } else {
while (posNode->data != posData) {
posNodeFront = posNode; posNode = posNodeFront->next; if (posNode == NULL) {
printf("没有找到相关结点无法删除"); return; } } posNodeFront->next = posNode->next; free(posNode); }}int main(void){
struct Node* list = createList(); insertNodeByHead(list, 1); insertNodeByHead(list, 2); insertNodeByHead(list, 3); printList(list); deleteNodeByAppoin(list, 2); printList(list); system("pause"); return 0;}

转载地址:http://wemji.baihongyu.com/

你可能感兴趣的文章
HQL语句大全(转)
查看>>
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb在java中的应用
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>