﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-ITvsET-文章分类-数据结构算法</title><link>http://www.cppblog.com/JackChen/category/16657.html</link><description>smiley</description><language>zh-cn</language><lastBuildDate>Tue, 17 May 2011 22:08:17 GMT</lastBuildDate><pubDate>Tue, 17 May 2011 22:08:17 GMT</pubDate><ttl>60</ttl><item><title>二叉树基本算法，遍历以及求高度、宽度等路径</title><link>http://www.cppblog.com/JackChen/articles/146292.html</link><dc:creator>天一程</dc:creator><author>天一程</author><pubDate>Thu, 12 May 2011 16:03:00 GMT</pubDate><guid>http://www.cppblog.com/JackChen/articles/146292.html</guid><wfw:comment>http://www.cppblog.com/JackChen/comments/146292.html</wfw:comment><comments>http://www.cppblog.com/JackChen/articles/146292.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/JackChen/comments/commentRss/146292.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/JackChen/services/trackbacks/146292.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 二叉树基本算法，遍历以及求高度、宽度等路径  //二叉树的相关算法，《数据结构习题与解析》7.3  //算法 49个，代码量1200+ ，时间9小时  &nbsp;  #include&lt;stdio.h&gt;  #include&lt;malloc.h&gt;  #include&lt;stdlib.h&gt;  &nbsp;  #define MaxSize 100  &nbsp;  ty...&nbsp;&nbsp;<a href='http://www.cppblog.com/JackChen/articles/146292.html'>阅读全文</a><img src ="http://www.cppblog.com/JackChen/aggbug/146292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/JackChen/" target="_blank">天一程</a> 2011-05-13 00:03 <a href="http://www.cppblog.com/JackChen/articles/146292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>帮助别人解决了一个技术题</title><link>http://www.cppblog.com/JackChen/articles/145694.html</link><dc:creator>天一程</dc:creator><author>天一程</author><pubDate>Wed, 04 May 2011 14:21:00 GMT</pubDate><guid>http://www.cppblog.com/JackChen/articles/145694.html</guid><wfw:comment>http://www.cppblog.com/JackChen/comments/145694.html</wfw:comment><comments>http://www.cppblog.com/JackChen/articles/145694.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/JackChen/comments/commentRss/145694.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/JackChen/services/trackbacks/145694.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; Oh，yeah！电脑上显示的结果正确的时候，心情有点小激动！毕竟花了自己一个多小时的时间解决了，其实问题困扰了自己一天。自己开始想的各种算法都不怎么好实现，最后无奈之下，自己潜意识的感觉这与排列组合算法有关，偶果断的去搜了下排列组合的算法，读了下，思路至少有点启发，但是脑子有点乱，看了下《拯救小兔》，计划看完后完成那个题目和自己的汉诺塔游戏，结果那个题目还是解决了，下面贴下题目和代码：（路过的各位大侠，如果有好的想法，也交流共享哈~）<br><br>题目：<br><span class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class=Apple-style-span style="FONT-SIZE: 14px; LINE-HEIGHT: 24px; FONT-FAMILY: arial, 宋体, sans-serif">
<pre id=question-content style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; ZOOM: 1; FONT-FAMILY: Arial; WORD-WRAP: break-word">n = 3
1: 1 1 1
2: 1 2     // 2 1 is considered the same solution
3: 3
n = 5
1: 1 1 1 1 1
2: 1 1 1 2
3: 1 1 3
4: 1 2 2
5: 1 4
6: 2 3
7: 5
就是 用户输入一个数字 就分解成上述的东西 上至下的顺序由长度决定 左到右由 数字大小决定</pre>
<p></span></span><br>偶的代码：（用了回溯的算法，递归的思想，每次求最后一个数字）<br>#include &lt;stdio.h&gt;<br>#include &lt;malloc.h&gt;</p>
<p>int minlast(int sum,int count)<br>{<br>&nbsp;if(sum%count==0)<br>&nbsp;&nbsp;return sum/count;<br>&nbsp;else<br>&nbsp;&nbsp;return sum/count+1;<br>}</p>
<p>int maxlast(int sum,int count)<br>{<br>&nbsp;return sum-(count-1);<br>}</p>
<p>int min(int a,int b)<br>{<br>&nbsp;if(a&lt;=b)<br>&nbsp;&nbsp;return a;<br>&nbsp;else <br>&nbsp;&nbsp;return b;<br>}</p>
<p>void getlast(int sum,int count,int lastcurrent,int a[],int Count)<br>{<br>&nbsp;static k=0;<br>&nbsp;a[count]=lastcurrent;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //保留上次的最后的一个字符<br>&nbsp;int i=0;<br>&nbsp;if(count==1 || count==0)<br>&nbsp;{<br>&nbsp;&nbsp;if(count==1)<br>&nbsp;&nbsp;&nbsp;a[count-1]=sum;<br>&nbsp;&nbsp;printf("\n%d: ",++k);<br>&nbsp;&nbsp;for(i=0;i&lt;Count;i++)<br>&nbsp;&nbsp;&nbsp;printf("%d ",a[i]);&nbsp;&nbsp;<br>&nbsp;}<br>&nbsp;else<br>&nbsp;{<br>&nbsp;&nbsp;for(i=min(lastcurrent,maxlast(sum,count))<br>&nbsp;&nbsp;&nbsp;;i&gt;=minlast(sum,count);i--)<br>&nbsp;&nbsp;&nbsp;getlast(sum-i,count-1,i,a,Count);<br>&nbsp;}<br>}</p>
<p><br>int main(void)<br>{<br>&nbsp;int a,i,j;<br>&nbsp;printf("Please Enter the number: ");<br>&nbsp;scanf("%d",&amp;a);</p>
<p>&nbsp;int *b=(int*)malloc(a*sizeof(int));</p>
<p>&nbsp;printf("After Computing:");</p>
<p>&nbsp;<br>&nbsp;for(i=a;i&gt;=1;i--)<br>&nbsp;&nbsp;for(j=maxlast(a,i);j&gt;=minlast(a,i);j--)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;getlast(a-j,i-1,j,b,i);<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;return 0;<br>}</p>
<img src ="http://www.cppblog.com/JackChen/aggbug/145694.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/JackChen/" target="_blank">天一程</a> 2011-05-04 22:21 <a href="http://www.cppblog.com/JackChen/articles/145694.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>2.2顺序表的算法</title><link>http://www.cppblog.com/JackChen/articles/144798.html</link><dc:creator>天一程</dc:creator><author>天一程</author><pubDate>Fri, 22 Apr 2011 12:34:00 GMT</pubDate><guid>http://www.cppblog.com/JackChen/articles/144798.html</guid><wfw:comment>http://www.cppblog.com/JackChen/comments/144798.html</wfw:comment><comments>http://www.cppblog.com/JackChen/articles/144798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/JackChen/comments/commentRss/144798.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/JackChen/services/trackbacks/144798.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include&nbsp;&lt;stdio.h&gt;#include&nbsp;&lt;iostream&gt;#define&nbsp;MaxSize&nbsp;50typedef&nbsp;int&nbsp;ElemType;typedef&nbsp;struct{&nbsp;&nbsp;&nbsp;&nbsp;ElemType&nbsp;data[MaxSize];&nbsp;&nbs...&nbsp;&nbsp;<a href='http://www.cppblog.com/JackChen/articles/144798.html'>阅读全文</a><img src ="http://www.cppblog.com/JackChen/aggbug/144798.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/JackChen/" target="_blank">天一程</a> 2011-04-22 20:34 <a href="http://www.cppblog.com/JackChen/articles/144798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>串的模式匹配</title><link>http://www.cppblog.com/JackChen/articles/144588.html</link><dc:creator>天一程</dc:creator><author>天一程</author><pubDate>Tue, 19 Apr 2011 14:05:00 GMT</pubDate><guid>http://www.cppblog.com/JackChen/articles/144588.html</guid><wfw:comment>http://www.cppblog.com/JackChen/comments/144588.html</wfw:comment><comments>http://www.cppblog.com/JackChen/articles/144588.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/JackChen/comments/commentRss/144588.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/JackChen/services/trackbacks/144588.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: //头文件的申明以及类型的定义#include&nbsp;&lt;cstring&gt;#include&nbsp;&lt;iostream&gt;#define&nbsp;MaxSize&nbsp;100typedef&nbsp;std::string&nbsp;SqString;//Brute-Force算法int&nbsp;index(SqString&nbsp;s,SqStri...&nbsp;&nbsp;<a href='http://www.cppblog.com/JackChen/articles/144588.html'>阅读全文</a><img src ="http://www.cppblog.com/JackChen/aggbug/144588.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/JackChen/" target="_blank">天一程</a> 2011-04-19 22:05 <a href="http://www.cppblog.com/JackChen/articles/144588.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>