数据结构 vs C#
csdn 的小盆友们 最近一直在玩 因为项目不是很忙 所以决定学习了 就从最开始的数据结构开始对于程序员来说 算法是很重要的
既然我是下菜鸟 那么就从最基本的开始吧
不知道 这样 有没有好处 用C#写 数据结构的算法
希望大家都来捧场啊 吧自己的代码上传 或者说一下 我的问题 在哪
加油啊 --------------------编程问答-------------------- 菜鸟帮顶 --------------------编程问答-------------------- LZ加油吧! --------------------编程问答-------------------- 所有的这些题目都是 从vedio 数据结构(清华严蔚敏)讲师的
就从简单的问题开始吧
1》 eg 2-3
la = "a,b,d,g,h,w,z";,lb ="b,c,e,d,u,y";他们的特点 递增,求lc 使他和la,lb 的具有相同的特性。
//make a new line lc has the same features of la,lb which increased gradually.
string la = "a,b,d,g,h,w,z";
string lb = "b,c,e,d,u,y";
// output lc?
i will put my code here, if you have a good one or any suggestions,please don't hesitate to reply to me
--------------------编程问答--------------------
哈哈 也可以来写一下啊 最好用c#
吼吼 --------------------编程问答--------------------
这么快 就有人回复 写写支持 恩 我想我会坚持 吼吼 监督啊 --------------------编程问答-------------------- 这个问题是说归并排序吧?
--------------------编程问答-------------------- 关于 string 转化成 array 的方法
String.Split 方法有6个重载函数:
1) public string[] Split(params char[] separator)
2) public string[] Split(char[] separator, int count)
3) public string[] Split(char[] separator, StringSplitOptions options)
4) public string[] Split(string[] separator, StringSplitOptions options)
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
1. public string[] Split(params char[] separator)
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
2. public string[] Split(char[] separator, int count)
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
3. public string[] Split(char[] separator, StringSplitOptions options)
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
4. public string[] Split(string[] separator, StringSplitOptions options)
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
需要注意的是没有重载函数public string[] Split(string[] separator),所以我们不能像VB.NET那样使用words.Split(","),而只能使用words.Split(',')!很多人都很奇怪为什么把双引号改为单引号就可以了?看了上边的重载函数该知道答案了吧^_^ --------------------编程问答-------------------- 从研究算法开始。不错 --------------------编程问答-------------------- 研究算法开始 --------------------编程问答--------------------
这个是在讲 线性表时候 举得例子 不是归并吧
--------------------编程问答-------------------- static void Main(string[] args)
{
//make a new line lc has the same features of la,lb which increased gradually.
string la = "a,b,d,g,h,w,z";
string lb = "b,c,e,d,u,y";
//lc?
string[] a = la.Split(new char[] {','});
string[] b = lb.Split(new char[]{','});
string[] c = new string[100];
int i = 0;
int j = 0;
int k = 0;
while (i < a.Length && j < b.Length)
{
if (a[i].CompareTo(b[j]) <= 0)
c[k] = a[i];
else
{
c[k] = b[j];
}
i++;
k++;
j++;
}
for(int w =0;w<c.Length;w++)
{
Console.Write(c[w]);
}
Console.ReadKey();
}
--------------------编程问答-------------------- 这是我第一次写的程序 输出结果是 abddhw 但是 不是我想要的结果 继续写
我想要的结果是 abcdeghuwyz
--------------------编程问答-------------------- 来转转 --------------------编程问答-------------------- 哦,那就是归并了
--------------------编程问答-------------------- 大家没事 闲着也一起http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=e2798a59-79d5-4833-9c57-87d46a8b907a写一下 啊 一起进步 交流一下啊 --------------------编程问答-------------------- 这个我还真去了,白板一个! --------------------编程问答-------------------- 可用reflector看.net framework中数据结构的实现,设计此类通用算法。需要一定设计和抽象能力 --------------------编程问答-------------------- 你想的太复杂了 就是简单的实现就是了 除了排序想要自己实现 别的就当是作业 用C#的现成的实现就行了 哈哈哈哈哈
--------------------编程问答--------------------
恩 就是 归并 哈哈哈
补充:.NET技术 , C#