码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 10.1作业


    1. #include
    2. #include
    3. #include
    4. /*
    5. * function:
    6. * 创建一个双向链表,将26个英文字母通过头插的方式插入,通过为尾删的方式读取并删除
    7. * @param [ in]
    8. * @param [out]
    9. * @return
    10. */
    11. typedef struct double_link_list{
    12. char data;
    13. struct double_link_list * pre;
    14. struct double_link_list * next;
    15. }node,*pnode;
    16. pnode listInit(){
    17. pnode H=(pnode)malloc(sizeof(node));
    18. if(NULL==H){
    19. printf("__%d__malloc failed",__LINE__);
    20. }
    21. H->data=0;
    22. H->pre=NULL;
    23. H->next=NULL;
    24. return H;
    25. }
    26. int headInsert(pnode H,char data){
    27. if(H==NULL){
    28. puts("null pont pass");
    29. return -1;
    30. }
    31. pnode newNode=(pnode)malloc(sizeof(node));
    32. newNode->data=data;
    33. newNode->next=H->next;
    34. if(H->next!=NULL)
    35. H->next->pre=newNode;
    36. H->next=newNode;
    37. newNode->pre=H;
    38. printf("%c insert success\n",H->next->data);
    39. return 0;
    40. }
    41. int tailDelete(pnode H){
    42. if(H==NULL){
    43. puts("null pont pass");
    44. return -1;
    45. }
    46. pnode p=H;
    47. //p指向最后一个节点
    48. while(p->next!=NULL){
    49. p=p->next;
    50. }
    51. while(p->pre!=NULL){
    52. printf("%c->",p->data);
    53. pnode del=p;
    54. p=p->pre;
    55. free(del);
    56. }
    57. return 0;
    58. }
    59. int print(pnode H){
    60. if(H==NULL){
    61. puts("null pont pass");
    62. return -1;
    63. }
    64. pnode p=H;
    65. //p指向最后一个节点
    66. while(p->next!=NULL){
    67. printf("%c->",p->next->data);
    68. p=p->next;
    69. }
    70. printf("last=%c\n",p->data);
    71. return 0;
    72. }
    73. int main(int argc, const char *argv[])
    74. {
    75. pnode H=listInit();
    76. for (char i='a'; i<='z'; i++)
    77. {
    78. headInsert(H,i);
    79. }
    80. tailDelete(H);
    81. //print(H);
    82. return 0;
    83. }

    运行结果:

  • 相关阅读:
    网络和Linux网络_2(套接字编程)socket+UDP网络通信代码
    Vue 3 中如何迁移从 Vue 2 的项目?
    AI助力快速定位数据库难题
    echarts-折线图配置详解
    树形数据增删改查
    解决:Typora上传图片后本地显示不出来
    设计模式之观察者模式
    探秘OpenAI的神奇之作:Sora技术揭秘
    优秀智慧园区案例 - 重庆AI PARK智慧创意园区,先进智慧园区建设方案经验
    Redis基础与高可用集群架构进阶详解
  • 原文地址:https://blog.csdn.net/weixin_53762703/article/details/133462320
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号