//链表的简单演示

namespace LinkList2
{
    
class Node
    {
        
public int data=0;
        
public Node next=null;
        
public Node(int data)
        {
            
this.data=data;
            next
=null;
        }
    }
    
    
class LinkList
    {
        
public Node header;
        
public LinkList()
        {
            header
=null;

        }
        
public void add(int data)
        {
            Node thisNode
=new Node(data);
            
if(header==null)
            {
                header
=thisNode;
            }
            
else
            {
                Node pointer
=header;
                
                
while(pointer.next!=null)
                {
                    pointer
=pointer.next;
                }
                pointer.next
=thisNode;
            }
        }
    }
    
    
    
class MainClass
    {
        
public static void Main(string[] args)
        {
            LinkList thisList
=new LinkList();
            thisList.add(
1);
            thisList.add(
2);
            thisList.add(
3);
            thisList.add(
4);
            thisList.add(
5);
            thisList.add(
7);
            
            Node pointer
=thisList.header;
            
while(pointer!=null)
            {
                Console.WriteLine(pointer.data);
                pointer
=pointer.next;
            }
            Console.ReadKey();
        }
    }
}
posted on 2008-06-04 22:28  LMT  阅读(262)  评论(0)    收藏  举报