惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
小众软件
小众软件
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
量子位
N
Netflix TechBlog - Medium
B
Blog
P
Proofpoint News Feed
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
AI
AI
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
M
MIT News - Artificial intelligence
Vercel News
Vercel News
D
DataBreaches.Net
P
Palo Alto Networks Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
The Hacker News
The Hacker News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
Attack and Defense Labs
Attack and Defense Labs
Recent Announcements
Recent Announcements
Hugging Face - Blog
Hugging Face - Blog
Webroot Blog
Webroot Blog
Cyberwarzone
Cyberwarzone
美团技术团队
博客园 - 司徒正美
Cloudbric
Cloudbric
J
Java Code Geeks
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
A
About on SuperTechFans

博客园 - 大天使泰瑞尔

通过反射机制控制前台的数据项的显示和隐藏 由partition看窗口函数 IE 6下CSS浮动样式的问题 转载一篇拼SQL字符串的语句 ASP.NET 2.0 中控件的简单异步回调 新手基础知识专用 今天终于学会了从客户端调用Web Service 学会了ASP.NET 2.0中的数据批量更新 - 大天使泰瑞尔 - 博客园 数据结构学习(6):队列 数据结构学习(4):栈 数据结构学习(3):堆化优先队列 数据结构学习(2):汉诺塔问题 数据结构学习(1):搜索二叉树 冒泡算法的三种JavaScript表示 YUI学习(1):ToolTip的用法 XML学习失误系列(2):分清节点性质,使用nodeValue JavaScript&DHTML特效学习(1):MSN提示框 YUI的Drap&Drop对IE7不支持 Gmail邮箱可以直接注册了
数据结构学习(5):链表
大天使泰瑞尔 · 2006-12-14 · via 博客园 - 大天使泰瑞尔

using System;

namespace DataStructure.LinkedList
{
    
/// <summary>
    
/// Class1 的摘要说明。
    
/// </summary>

    public class ListNode
    
{
        
public string airport;
        
public ListNode link;
        
public ListNode previous;
    }

    
public class LinkedList
    
{
        
public int length;//结点数
        public ListNode firstNode;

        
public int size()
        
{
            
return length;
        }

        
        
public void insertNewSecondNode(string airportCode)
        
{
            
if (length==0return;
            ListNode newNode;
//让newNode成为一个ListNode变量
            newNode=new ListNode();//在newNode中存储一个新结点
            newNode.airport=airportCode;
            newNode.link
=firstNode.link;//让newNode连接到L的次结点
            newNode.previous=firstNode;
            firstNode.link
=newNode;//让L的第一个结点连接到newNode
            firstNode.previous=null;//
            length++;
        }


        
public ListNode listSearch(string airportCode)
        
{
            ListNode N;
            N
=firstNode;
            
while(N!=null)
            
{
                
if(airportCode.Equals(N.airport))
                
{
                    
return N;
                }

                
else
                    N
=N.link;

            }

            
return N;
        }


        
public void deleteLastNode()
        
{
            ListNode previousNode,currentNode;
            
if(firstNode!=null)
            
{
                
if(firstNode.link==null)
                
{
                    firstNode
=null;
                    length
--;
                }

                
else
                
{
                    previousNode
=firstNode;
                    currentNode
=firstNode.link;

                    
while(currentNode.link!=null)//前移两个指针
                    {
                        previousNode
=currentNode;
                        currentNode
=currentNode.link;
                    }

                    previousNode.link
=null;//把倒数第二个结点指向空
                    length--;
                }

            }

        }

        
public void insertNewLastNode(string airportCode)
        
{
            ListNode N
=new ListNode();//通过airport==airportNode和link==null构造
            N.airport=airportCode;
            N.link
=null;
            
//将N作为新的末端结点插入
            if(firstNode==null)
                firstNode
=N;
            
else
            
{
                
//利用结点指针P定位链表的末端结点
                ListNode P=firstNode;
                
while(P.link!=null)
                
{
                    P
=P.link;
                }


                
//最后将结点N链接到末端
                P.link=N;
            }

            length
++;
        }

        
public void print()
        
{
            ListNode N;
            
//首先,打印一个左括号
            Console.WriteLine("(");
            N
=firstNode;
            
//假如N没有指向空结点,则打印的airport
            
//并将N前移指向链表的下一个结点
            while(N!=null)
            
{
                Console.WriteLine(N.airport);
                N
=N.link;
                
if(N!=null)
                
{
                    Console.WriteLine(
",");
                }

            }

            Console.WriteLine(
")");
        }


        
public void  insertNewFirstNode(string A)
        
{
            ListNode N
=new ListNode();
            N.airport
=A;
            N.link
=firstNode;
            N.previous
=null;
            firstNode
=N;
        }

        
public LinkedList Clone()
        
{
            LinkedList NL
=new LinkedList();
            NL.firstNode
=this.firstNode;
            NL.length
=this.length;
            
return NL;
        }

        
public void deleteFirst()
        
{
            firstNode
=firstNode.link;
        }


        
        
public static void Main()
        
{
            LinkedList L
=new LinkedList();
            L.insertNewLastNode(
"DUS");
            L.insertNewLastNode(
"ORD");
            L.insertNewLastNode(
"SAN");
            
            L.print();
            L.insertNewFirstNode(
"CHN");
            L.print();
            L.deleteFirst();
            L.print();
            LinkedList NL
=L.Clone();
            NL.print();
            Console.WriteLine(L.length);
            Console.ReadLine();
            
        }


        
public void reverse()
        
{
            firstNode
=reverse1(firstNode);
//            Reverse采取下面的辅助方法reverse(L),让LinkedList头结点的firstNode
//            域指向链表L
        }

        
public ListNode reverse1(ListNode L)
        
{
            
if(L==null)
            
{
                
return null;//基本状态
            }

            
else
            
{
                ListNode head
=L;
                ListNode tail
=L.link;//将L划分为head和tail
                head.link=null;//掉转
                return concat(reverse1(tail),head);//递归
            }

        }


        
public ListNode concat(ListNode L1,ListNode L2)
        
{
            
if(L1==null)
                
return L2;//基本状态
            else
            
{
                L1.link
=concat(L1.link,L2);//递归
                return L1;
            }

        }

    }

}