熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#單鏈表

2013-11-13 10:01:47  來源: .NET編程 

  using System;

   using SystemCollectionsGeneric;

   using SystemText;

  

   namespace bishi

   {

       public class Node

       {

           public object element;

           public Node link;

  

           public Node()

           {

               element = null;

               link = null;

  

           }

  

           public Node(object item)

           {

               element = item;

               thislink = null;

           }

  

       }

  

       public class LinkList

       {

           public Node head;

           public LinkList Next;

  

           public LinkList()

           {

               head = new Node(header);

           }

  

           public  Node findNode(object item)

           {

               Node current = new Node();

               current=head;

               while (currentelement != item)

               {

                   current = currentlink;

               }

               return current;

  

           }

  

           public void insertNode(object itemobject after)

           {

               Node current = new Node();

               Node newNode=new Node(item);

               current = findNode(after);

               if (current != null)

               {

                   newNodelink = currentlink;

                   currentlink = newNode;

               }

           }

  

          public  void Del(object item)

           {

               Node current = new Node();

               current = findPre(item);

               Node pre = new Node();

             //  Node after = new Node();

               if (current != null)

                   currentlink = currentlinklink;

           }

           public Node findPre(object item)

           {

               Node current = head;

               while (!(currentlinkelement != item) && (currentlink != null))

               {

                   current = currentlink;

               }

               return current;

           }

           public void PrintList()

           {

               Node current = new Node();

               current = thishead;

               while (current != null)

               {

                   ConsoleWriteLine(currentelement);

                   current = currentlink;

               }

           }

       }

  

       class pro

       {

           static void Main(string[] args)

           {

               Node firstNode = new Node(firstNode);

               Node secNode = new Node(secNode);

               Node thiNode = new Node();

               firstNodelink = secNode;

               secNodelink = thiNode;

               thiNodelink = null;

               LinkList myList = new LinkList();

               myListheadlink = firstNode;

               myListPrintList();

               myListinsertNode(hanwujibabyfirstNode);

               myListPrintList();

               myListDel(hanwujibaby);

               myListPrintList();

               SystemThreadingThreadSleep();

           }

       }

     }


From:http://tw.wingwit.com/Article/program/net/201311/12322.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.