摘要:下面是希赛软考学院为大家提供的软考程序员教程重点提炼之反向链表,希望能帮助学友们
下面是希赛软考网为大家提供的软考程序员教程重点提炼之反向链表,希望能帮助学友们。
class Link//this class reverse the LinkedList
{public int a;
public Link next;
}
class createLink//the class create the LinkedList
{
Link header=null;
Link p=null;
Link temp=null;
Link l=null;//Link k=null;
Link g=null;
public void create()
{string str;
int i;
Console.WriteLine("Please enter number:");
str=Console.ReadLine();
while(str!="y")
{i=Convert.ToInt32(str);
temp=new Link();
temp.a=i;
temp.next=null;
if(g==null)
g=temp;
if(header==null)
header=temp;
if(p==null)
p=temp;
else
{p.next=temp;
p=p.next;
}
Console.WriteLine("please enter number:");
str=Console.ReadLine();
}
}
public void display()
{while(header!=null)
{Console.WriteLine(header.a);
header=header.next;
}
}
public void reversed()//the mothod reversed the LinkedList
{Link k=null;
Link tmp=null;
Link com=null;
if(tmp==null)
tmp=header.next;
while(tmp!=null)
{//if(com==null)
//com=header;
l=tmp;
if(k==null)
{header.next=null;
k=header;
}
com=header;
header=l;
tmp=l.next;
l.next=com;
}
}
public void show()
{while(l!=null)
{Console.WriteLine(l.a);
l=l.next;
}}}
class Tester
{static void Main()
{createLink cl=new createLink();
cl.create();
//cl.display();
cl.reversed();
cl.show();
}}}
希赛软考网,拥有十四年软考培训经验,希赛网一直坚持自主研发,将丰富的软考培训经验有效融入教程研发过程,自成体系的软考在线题库(软考历年真题)、软考培训教材和软考视频教程,多样的培训方式包括在线辅导、面授、和,使考生的学习更具系统性,辅导更具针对性。采用全程督学机制,,软考平均通过率在全国。
软考备考资料免费领取
去领取