代码拉取完成,页面将自动刷新
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>博客</title>
<url>/blog/2020/04/22/4-22%E9%A6%96%E7%AB%A0/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\blog\assets\css\APlayer.min.css"><script src="\blog\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>欢迎阅读我的博客,博客搭建时间: 2020/4/22<br>部署于: Github pages (gitee: cedar_i.gitee.io)<br>基于框架: Hexo<br>主题: Next<br>美化: 个人<br>今后的学习记录都会呈现于此,<br>欢迎大家互相学习。</p>
<a id="more"></a>
<h2 id="个人信息"><a href="#个人信息" class="headerlink" title="个人信息"></a>个人信息</h2><p>QQ:1248558099<br><img src="../../../../../../images/tx.jpg" alt="a"></p>
]]></content>
<tags>
<tag>前言</tag>
</tags>
</entry>
<entry>
<title>数据结构-单链表</title>
<url>/blog/2020/04/22/4-24%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-%E5%8D%95%E9%93%BE%E8%A1%A8/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\blog\assets\css\APlayer.min.css"><script src="\blog\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="数据结构-单链表"><a href="#数据结构-单链表" class="headerlink" title="数据结构-单链表"></a>数据结构-单链表</h3><h1 id="单链表"><a href="#单链表" class="headerlink" title="单链表"></a>单链表</h1><p>单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数据元素。<br>链表中的数据是以结点来表示的<br>每个结点的构成:元素(数据元素的映象) + 指针(指示后继元素存储位置)<br>元素就是存储数据的存储单元,指针就是连接每个结点的地址数据</p>
<h1 id="链表定义"><a href="#链表定义" class="headerlink" title="链表定义"></a>链表定义</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">typedef int ElemType;</span><br><span class="line">typedef struct Node</span><br><span class="line">{</span><br><span class="line"> ElemType data;</span><br><span class="line"> struct Node *next;</span><br><span class="line">}LNode,*LinkList;//定义单链表结点结构体</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h1 id="初始化单链表"><a href="#初始化单链表" class="headerlink" title="初始化单链表"></a>初始化单链表</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">int ListInit_L(LinkList &L) //初始化单链表,建立一个带头结点的单链表</span><br><span class="line">{</span><br><span class="line"> L = (LinkList)malloc(sizeof(Node));</span><br><span class="line"> if(!L) exit(0);//创建失败退出.除非系统出错- -</span><br><span class="line"> L->next=NULL;</span><br><span class="line"> L->data=-1;</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h1 id="头插法"><a href="#头插法" class="headerlink" title="头插法"></a>头插法</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">void ListInit_Creadhead(LinkList &L) //头插法</span><br><span class="line">{</span><br><span class="line"> int n;</span><br><span class="line"> LinkList p,q;</span><br><span class="line"> p=L;</span><br><span class="line"> printf("输入n和n个数字:\n");</span><br><span class="line"> scanf("%d",&n);</span><br><span class="line"> printf("输入%d个数字\n",n);</span><br><span class="line"> while(n--)</span><br><span class="line"> {</span><br><span class="line"> q=(LinkList)malloc(sizeof(LNode));</span><br><span class="line"> scanf("%d",&q->data);</span><br><span class="line"> q->next=p->next;</span><br><span class="line"> p->next=q;</span><br><span class="line"> p=q;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h1 id="尾插法"><a href="#尾插法" class="headerlink" title="尾插法"></a>尾插法</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">void ListInit_Creadtail(LinkList &L) //尾插法</span><br><span class="line">{</span><br><span class="line"> int n;</span><br><span class="line"> LinkList p,s;</span><br><span class="line"> p=L;</span><br><span class="line"> printf("输入n和n个数字:\n");</span><br><span class="line"> scanf("%d",&n);</span><br><span class="line"> printf("输入%d个数字\n",n);</span><br><span class="line"> while(n--)</span><br><span class="line"> {</span><br><span class="line"> s=(LinkList)malloc(sizeof(Node));</span><br><span class="line"> scanf("%d",&s->data);</span><br><span class="line"> s->next=p->next;</span><br><span class="line"> p->next=s;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h1 id="按位插入"><a href="#按位插入" class="headerlink" title="按位插入"></a>按位插入</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">void LinkedList_Insert(LinkList &L,int i,int key) //按位插入</span><br><span class="line">{</span><br><span class="line"> LinkList p,s;//定义所需结点</span><br><span class="line"> p=L;</span><br><span class="line"> int j=1;</span><br><span class="line"> while(j<i)</span><br><span class="line"> {</span><br><span class="line"> p=p->next;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> s = (LinkList)malloc(sizeof(Node));</span><br><span class="line"> s->data=key;</span><br><span class="line"> s->next=p->next;</span><br><span class="line"> p->next=s;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h1 id="删除i位置上的元素"><a href="#删除i位置上的元素" class="headerlink" title="删除i位置上的元素"></a>删除i位置上的元素</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">void LinkList_delete(LinkList L, int i)//删除i位置上的元素 </span><br><span class="line">{</span><br><span class="line"> int j;</span><br><span class="line"> LinkList p, q;</span><br><span class="line"> p = L;</span><br><span class="line"> j = 1;</span><br><span class="line"> while (j<i)</span><br><span class="line"> {</span><br><span class="line"> p = p->next;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> q = p->next;</span><br><span class="line"> p->next = p->next->next;</span><br><span class="line"> free(q);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="全代码"><a href="#全代码" class="headerlink" title="全代码"></a>全代码</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">#include<stdio.h></span><br><span class="line">#include<stdlib.h></span><br><span class="line">typedef int ElemType;</span><br><span class="line">typedef struct Node</span><br><span class="line">{</span><br><span class="line"> ElemType data;</span><br><span class="line"> struct Node *next;</span><br><span class="line">}LNode,*LinkList;//定义单链表结点结构体</span><br><span class="line"></span><br><span class="line">void LinkList_Print(LinkList L)//输出单链表和链表长度</span><br><span class="line">{</span><br><span class="line"> int num = 0;</span><br><span class="line"> LinkList p;</span><br><span class="line"> p=L->next;</span><br><span class="line"> while(p)</span><br><span class="line"> {</span><br><span class="line"> num++;</span><br><span class="line"> printf("%d ",p->data);</span><br><span class="line"> p=p->next;</span><br><span class="line"> }</span><br><span class="line"> printf("长度为:%d\n",num);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">void LinkList_Find(LinkList L,int x)//查找第x个位置的值</span><br><span class="line">{</span><br><span class="line"> LinkList p;</span><br><span class="line"> p=L;</span><br><span class="line"> int i=1;</span><br><span class="line"> while(p->next &&p->next->data!=x)</span><br><span class="line"> {</span><br><span class="line"> p=p->next;</span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> if(p->next)</span><br><span class="line"> printf("%d的位置为:%d\n",x,i);</span><br><span class="line"> else</span><br><span class="line"> printf("没找到!!\n\n");</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">void LinkList_sort(LinkList &L)</span><br><span class="line">{</span><br><span class="line"> LinkList p,q;</span><br><span class="line"> int temp;</span><br><span class="line"> for(p=L;p->next!=NULL;p=p->next)</span><br><span class="line"> {</span><br><span class="line"> for(q=p->next;q!=NULL;q=q->next)</span><br><span class="line"> {</span><br><span class="line"> if(p->data>q->data)</span><br><span class="line"> {</span><br><span class="line"> temp=p->data;</span><br><span class="line"> p->data=q->data;</span><br><span class="line"> q->data=temp;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> }</span><br><span class="line"> printf("排序成功!\n");</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">void LinkList_Deletesame(LinkList L)//删除相同的元素</span><br><span class="line">{</span><br><span class="line"> LinkList_sort(L);//排序........</span><br><span class="line"> LinkList p,q,s;</span><br><span class="line"> p=L;</span><br><span class="line"> q=L->next;</span><br><span class="line"> while(q->next)</span><br><span class="line"> {</span><br><span class="line"> if(q->data==q->next->data)</span><br><span class="line"> {</span><br><span class="line"> p->next=q->next;</span><br><span class="line"> s=q;</span><br><span class="line"> q=q->next;</span><br><span class="line"> free(s);</span><br><span class="line"> }</span><br><span class="line"> else</span><br><span class="line"> {</span><br><span class="line"> p=p->next;</span><br><span class="line"> q=q->next;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> printf("删除成功!!!!\n");</span><br><span class="line">}</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">int ListInit_L(LinkList &L) //初始化单链表,建立一个带头结点的单链表</span><br><span class="line">{</span><br><span class="line"> L = (LinkList)malloc(sizeof(Node));</span><br><span class="line"> if(!L) exit(0);//创建失败退出.除非系统出错- -</span><br><span class="line"> L->next=NULL;</span><br><span class="line"> L->data=-1;</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">void ListInit_Creadhead(LinkList &L) //头插法</span><br><span class="line">{</span><br><span class="line"> int n;</span><br><span class="line"> LinkList p,q;</span><br><span class="line"> p=L;</span><br><span class="line"> printf("输入n和n个数字:\n");</span><br><span class="line"> scanf("%d",&n);</span><br><span class="line"> printf("输入%d个数字\n",n);</span><br><span class="line"> while(n--)</span><br><span class="line"> {</span><br><span class="line"> q=(LinkList)malloc(sizeof(LNode));</span><br><span class="line"> scanf("%d",&q->data);</span><br><span class="line"> q->next=p->next;</span><br><span class="line"> p->next=q;</span><br><span class="line"> p=q;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">void ListInit_Creadtail(LinkList &L) //尾插法</span><br><span class="line">{</span><br><span class="line"> int n;</span><br><span class="line"> LinkList p,s;</span><br><span class="line"> p=L;</span><br><span class="line"> printf("输入n和n个数字:\n");</span><br><span class="line"> scanf("%d",&n);</span><br><span class="line"> printf("输入%d个数字\n",n);</span><br><span class="line"> while(n--)</span><br><span class="line"> {</span><br><span class="line"> s=(LinkList)malloc(sizeof(Node));</span><br><span class="line"> scanf("%d",&s->data);</span><br><span class="line"> s->next=p->next;</span><br><span class="line"> p->next=s;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">void LinkedList_Insert(LinkList &L,int i,int key) //按位插入</span><br><span class="line">{</span><br><span class="line"> LinkList p,s;//定义所需结点</span><br><span class="line"> p=L;</span><br><span class="line"> int j=1;</span><br><span class="line"> while(j<i)</span><br><span class="line"> {</span><br><span class="line"> p=p->next;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> s = (LinkList)malloc(sizeof(Node));</span><br><span class="line"> s->data=key;</span><br><span class="line"> s->next=p->next;</span><br><span class="line"> p->next=s;</span><br><span class="line">} </span><br><span class="line">void LinkList_delete(LinkList L, int i)//删除i位置上的元素 </span><br><span class="line">{</span><br><span class="line"> int j;</span><br><span class="line"> LinkList p, q;</span><br><span class="line"> p = L;</span><br><span class="line"> j = 1;</span><br><span class="line"> while (j<i)</span><br><span class="line"> {</span><br><span class="line"> p = p->next;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> q = p->next;</span><br><span class="line"> p->next = p->next->next;</span><br><span class="line"> free(q);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">void LinkList_find2(LinkList L, int i)//查找i位置上的元素 </span><br><span class="line">{</span><br><span class="line"> int j=0;</span><br><span class="line"> LinkList p;</span><br><span class="line"> p = L;</span><br><span class="line"> while (j<i)</span><br><span class="line"> {</span><br><span class="line"> p = p->next;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> if(p!=NULL)</span><br><span class="line"> printf("第%d位置上的值为:%d\n",i,p->data);</span><br><span class="line"> else</span><br><span class="line"> printf("元素不存在");</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">void menu()</span><br><span class="line">{</span><br><span class="line"> printf("\n");</span><br><span class="line"> printf("根据按键选择相应的操作:\n");</span><br><span class="line"> printf("1、输出单链表及其长度\n");</span><br><span class="line"> printf("2、查找元素在表中的位置\n");</span><br><span class="line"> printf("3、删除第i个结点:\n");</span><br><span class="line"> printf("4、删除相同的值(自动排序)作业之外:\n");</span><br><span class="line"> printf("5、在位置i 插入新的元素key\n");</span><br><span class="line"> printf("0、退出:\n");</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">void main()</span><br><span class="line">{</span><br><span class="line"> int ID,x;</span><br><span class="line"> LinkList L;</span><br><span class="line"> ListInit_L(L); //带头结点的初始化</span><br><span class="line"> printf("请选择你要插入的方式\n1、头插法\n2、尾插法\n"); //选择插入方式</span><br><span class="line"> scanf("%d",&ID);</span><br><span class="line"> switch(ID)</span><br><span class="line"> {</span><br><span class="line"> case 1:ListInit_Creadhead(L);break; //头插法</span><br><span class="line"> case 2:ListInit_Creadtail(L);break; //尾插法</span><br><span class="line"> }</span><br><span class="line"> menu(); //菜单</span><br><span class="line"> while(ID)</span><br><span class="line"> {</span><br><span class="line"> scanf("%d",&ID);</span><br><span class="line"> switch(ID)</span><br><span class="line"> {</span><br><span class="line"> case 1:LinkList_Print(L); //表长和 输出函数。弄一起了</span><br><span class="line"> break;</span><br><span class="line"> case 2:</span><br><span class="line"> printf("请输入要查找的元素:\n");</span><br><span class="line"> scanf("%d",&x);</span><br><span class="line"> LinkList_Find(L,x);</span><br><span class="line"> break;</span><br><span class="line"> case 3:</span><br><span class="line"> printf("请输入要删除的位置:\n");</span><br><span class="line"> scanf("%d",&x);</span><br><span class="line"> LinkList_delete(L,x); //删除操作</span><br><span class="line"> break;</span><br><span class="line"> case 4:LinkList_Deletesame(L); //删除相同的值.加强版本。自动排序。。不在作业范围内</span><br><span class="line"> break;</span><br><span class="line"> case 5:</span><br><span class="line"> int a,b;</span><br><span class="line"> printf("请输入你要插入的位置");//位插</span><br><span class="line"> scanf("%d",&a);</span><br><span class="line"> printf("请输入你要插入的值");</span><br><span class="line"> scanf("%d",&b);</span><br><span class="line"> LinkedList_Insert(L,a,b);</span><br><span class="line"> break;</span><br><span class="line"> case 6:</span><br><span class="line"> printf("请输入要查找的位置:\n");//查找位置</span><br><span class="line"> scanf("%d",&x);</span><br><span class="line"> LinkList_find2(L,x); </span><br><span class="line"> break;</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<!--
<script>
console.error("Error: [hexo-tag-aplayer] Specified asset file not found (夏天的风.png)");
</script> -->
]]></content>
<categories>
<category>C语言</category>
</categories>
<tags>
<tag>C语言</tag>
<tag>数据结构</tag>
<tag>单链表</tag>
</tags>
</entry>
<entry>
<title>5-7二叉树的应用</title>
<url>/blog/2020/05/07/5-7%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%BA%94%E7%94%A8/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\blog\assets\css\APlayer.min.css"><script src="\blog\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h1 id="定义二叉树结点和结点指针"><a href="#定义二叉树结点和结点指针" class="headerlink" title="定义二叉树结点和结点指针"></a>定义二叉树结点和结点指针</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">typedef struct BiTNode</span><br><span class="line">{</span><br><span class="line"> char data;</span><br><span class="line"> struct BiTNode *lchild,*rchild; //定义出左孩子和右孩子</span><br><span class="line">}BiTNode,*BiTree;</span><br></pre></td></tr></table></figure>
<hr>
<h1 id="创建二叉树"><a href="#创建二叉树" class="headerlink" title="创建二叉树"></a>创建二叉树</h1><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">void CreateBiTree(BiTree *T) //二叉树的创建(前序输入)</span><br><span class="line">{</span><br><span class="line"> char ch; </span><br><span class="line"> scanf("%c",&ch); //记录输入的值</span><br><span class="line"> if(ch=='.') //如果值为 . 则输入的为空值,并退出递归</span><br><span class="line"> *T=NULL;</span><br><span class="line"> else</span><br><span class="line"> {</span><br><span class="line"> *T=(BiTree)malloc(sizeof(BiTNode)); //为T分配空间</span><br><span class="line"> if(*T==NULL)//if (!*T) //保险判断,以防进入的为空值</span><br><span class="line"> exit(-1); //退出递归</span><br><span class="line"> (*T)->data=ch; //将值赋值到树中</span><br><span class="line"> CreateBiTree(&(*T)->lchild); //递归左孩子</span><br><span class="line"> CreateBiTree(&(*T)->rchild); //递归右孩子</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<a id="more"></a>]]></content>
<categories>
<category>C语言</category>
</categories>
<tags>
<tag>C语言</tag>
<tag>数据结构</tag>
<tag>二叉树</tag>
</tags>
</entry>
</search>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。