链栈的构建—数据结构算法
功能截图:
部分源码,没有main主函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #include <stdio.h> #include <stdlib.h> typedef struct List { int data; struct List *next; }list,*p_list; void creat_list(list **p) { int item; list *temp; list *target; printf( "输入节点的值,输入0结束\n" ); while (1) { scanf( "%d" ,&item); if (item==0) return ; if (*p==NULL) { *p=(list *)malloc( sizeof (list)); if (!*p)exit(0); (*p)->data=item; (*p)->next=*p; } else { for (target=*p;target->next!=*p;target=target->next); temp=(list *)malloc( sizeof (list)); if (!temp)exit(0); temp->data=item; temp->next=*p; target->next=temp; } } } void insert(list **pNode, int place, int num) { list *temp,*target; int i; if (place==1) { temp=(list *)malloc( sizeof (list)); if (!temp)exit(0); temp->data=num; for (target=*pNode;target->next!=*pNode;target=target->next); temp->next=*pNode; target->next=temp; *pNode=temp; } else { for (i=1,target=*pNode;target->next!=*pNode&&i!=place-1;target=target->next,i++); temp=(list *)malloc( sizeof (list)); temp->data=num; temp->next=target->next; target->next=temp; } } void Delete(list **pNode, int place) { list *temp,*target; int i; temp=*pNode; if (temp==NULL) { printf( "这是一个空指针 无法删除\n" ); return ; } if (place==1) { for (target=*pNode;target->next!=*pNode;target=target->next); temp=*pNode; *pNode=(*pNode)->next; target->next=*pNode; free(temp); } else { for (i=1,target=*pNode;target->next!=*pNode&&i!=place-1;target=target->next,i++); if (target->next==*pNode) { for (target=*pNode;target->next->next!=*pNode;target=target->next); temp=target->next; target->next=*pNode; printf( "数字太大删除尾巴\n" ); free(temp); } else { temp=target->next; target->next=temp->next; free(temp); } } } int findval(list *pNode, int val) { int i=1; list *node; node=pNode; while (node->data!=val&&node->next!=pNode) { i++; node=node->next; } if (node->next==pNode&&node->data!=val) { return -1; } return i; } void show(list *p) { list *temp; temp=p; do { printf( "%5d" ,temp->data); temp=temp->next; } while (temp!=p); printf( "\n" ); } |
注意这里仅为部分代码。获取源码请关注“值南针”微信公众号:可用电脑微信关注或手机关注(要最新版微信pc端)。在电脑方便。直接下载源码。
点击想要的算法
点击下载直接就可以用的。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话