﻿ 一道求單向鏈表倒數第N個結點的算法題_電腦知識網

# 一道求單向鏈表倒數第N個結點的算法題

2013-11-13 09:49:27  來源: .NET編程
{
class Program
{
static void Main(string[] args)
{

while (true)
{
ConsoleWriteLine(請輸入你需要得到倒數第幾個元素最大為輸入其它程序將出錯);
string iNum = ConsoleReadLine()ToString();
if (iNum ==Q)
{
return ;
}
int index = ConvertToInt(iNum);

Node node = new Node();
for (int i = ; i (i);
node = nodeNexNode;
}

ConsoleWriteLine(退出請按輸入Q繼續測試請輸入測試位置Num);

}
}
}
class Node
{

private T value;

public T Value
{
get { return thisvalue; }
set { thisvalue = value; }
}
private Node nextNode;

public Node NexNode
{
get { return nextNode; }
set { nextNode = value; }
}
public Node(T value)
{
thisvalue = value;
}
}
{

{
get { return headNode; }
set { headNode = value; }
}

{
}
public Node GetValue(Node node Node node)
{
while (true)
{
if (nodeNexNode == null)
{
return node;
}
node = nodeNexNode;
node = nodeNexNode;
}
}
public Node GetNode(int index bool flag)
{
if (!flag)
{
return null;
}
else
{
Node node = headNode;
Node node node;
node = node = headNode;
int p p tmp;
p = p = tmp = ;
while (true)
{
if (nodeNexNode == null)
{
p = tmp;
node = node;
return GetValue(node node);
}
else if (p tmp == index)
{
node = node;
p = tmp;
node = node;
tmp = p;
p++;

node = nodeNexNode;
}
else
{

p++;
node = nodeNexNode;

}

}

}
}
}
}

From:http://tw.wingwit.com/Article/program/net/201311/11676.html
相關文章
没有相关文章