zoukankan      html  css  js  c++  java
  • 链表

    //链表1

    public class Node

    { public int Data;

    public Node Next;

    public Node()

    {

    Data=default(int);

    Next=null;

    }

    public Node(int value)

    {

    Data=value;

    Next=null;

    }

    }

    //链表2

    public class LinkList

    {

    private Node _head;

    private int _count;

    public LinkList()

    {

    _head=new Node();

    _count=0;

    }

    //添加

    public void AddItem(Node newNode)

    {

    Node Db=_head;

    while(Db.Next!=null)

    {

    Db=Db.Next;

    }

    Db.Next=newNode;

    _count++;

    }

    //获取长度

    public int Getlength()

    {

    return _count;

    }

    //插入

    public void Insert(int index,Node newNode)

    {

    if(index<=||index>_count)

    {

    console,writeline("搓比");

    return;

    }

    Node Ls=_head;

    for(int i=0;i<index;i++)

    {

    Ls=Ls.next;

    }

    newnode.next=ls.next;

    ls.next=newnode;

    _count++;

    }

    //删除

    public Node RemoveAt(int index)

    {

    Node returnvalue=default(Node);

    {

    if(index<0||index>_count)

    {

    console.writeline("are you sb?");

    return returnvalue;

    }

    Node mm=_head;

    for(int i=0;i<index;i++)

    {

    mm=mm.next;

    }

    Node xmm=mm.next;

    mm.next=mm.next.next;

    mm.next.next=null;

    _count--;

    return xmm;

    }

    //遍历

    public void ShowItem(Action<int,int> md)

    {

    if(_count==0)

    {

    console.writeline("你确定能行?");

    return;

    }

    Node mm=_head/next;

    for(int i=0;i<_count;i++)

    {

    md(i,mm.Data);

    }

    mm=mm.next;

    }

    //链表倒序

    public void Dx()

    {

    Node node =_head;

    Node up=null;

    Node down;

    node =node.next;

    while(node!=null)

    {

    down=node.next;

    node.next=up;

    up=node;

    node=down;

    }

    _head.next=up;

    }

    }

    }

  • 相关阅读:
    FR #3题解
    L3-005. 垃圾箱分布
    L2-004. 这是二叉搜索树吗?
    L2-002. 链表去重
    L1-009. N个数求和
    L3-003. 社交集群
    L3-004. 肿瘤诊断
    L2-001. 紧急救援
    L3-002. 堆栈
    L2-007. 家庭房产
  • 原文地址:https://www.cnblogs.com/qipei/p/9885246.html
Copyright © 2011-2022 走看看