c#mysql查询重复数据结构_C#数据结构算法 合链两个链表并去除链表中的重复数据...

合链两个链表并去除链表中的重复数据

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingDSList;//这个是自己写的算法生成的引用

namespace_20100701

{

class Program

{

static void Main(string[] args)

{

LinkList LLa = new LinkList();

LinkList LLb = new LinkList();

LinkList LLc = new LinkList();

LLa.Append(9);

LLa.Append(10);

LLa.Append(5);

LLa.Append(4);

LLa.Append(1);

Console.WriteLine("LLa中的数据:");

showDatas(LLa);

LLb.Append(15);

LLb.Append(13);

LLb.Append(10);

LLb.Append(10);

LLb.Append(4);

LLb.Append(2);

Console.WriteLine("LLb中的数据:");

showDatas(LLb );

LLc= Merge(LLa, LLb);

Console.WriteLine("合并后的数据:");

showDatas(LLc);

delRepeat(LLc);

Console.WriteLine("去重后的数据:");

showDatas(LLc);

Console.ReadKey();

}

static LinkList Merge(LinkList LLa, LinkList LLb)//将LLa,LLb链表合并后存入LLc升序

{

LinkList LLc = new LinkList();

int i=LLa.GetLength()-1;

int j=LLb.GetLength()-1;

int k=0;

while (i >= 0 && j >= 0)

{

if (LLa.GetElem(i)< LLb.GetElem(j))

{

LLc.Append(LLa.GetElem(i--));

k++;

}

else

{

LLc.Append(LLb.GetElem(j--));

k++;

}

}

while (i+1> 0)

{

LLc.Append(LLa.GetElem(i--));

}

while (j+1 > 0)

{

LLc.Append(LLb.GetElem(j--));

}

return LLc;

}

static void showDatas(LinkList list)//显示数据

{

StringBuilder strBuilder = new StringBuilder();

Node currentNode = list.Head;

while (currentNode != null)

{

strBuilder.Append(currentNode.Data+" ");

currentNode = currentNode.Next;

}

Console.WriteLine(strBuilder.ToString());

}

static void delRepeat(LinkList list)//去除链表中重复数据

{

Node current = list.Head;

while (current!= null)

{

while (current.Next != null)

{

if (current.Data ==current.Next.Data)

{

int i = list.Locate(current.Next.Data);

list.Delete(i);

}

current = current.Next;

}

current = current.Next;

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值