• 数据结构java实现之双端链表


     1 package com.liu.Link;
     2 
     3 //双端链表
     4 public class FirstLastList {
     5     private LinkLast first;
     6     private LinkLast last;
     7     public FirstLastList()
     8     {
     9         first = null;
    10         last = null;
    11     }
    12     
    13     public boolean isEmpty()
    14     {
    15         return first == null;
    16     }
    17     
    18     public void insertFirst(long d)
    19     {
    20         LinkLast newLink = new LinkLast(d);
    21         if(isEmpty())
    22         {
    23             last = newLink;
    24         }
    25         newLink.next = first;
    26         first = newLink;
    27     }
    28     
    29     public long deleteFirst()
    30     {
    31         long temp = first.dData;
    32         if(first.next == null)
    33             last = null;
    34         first = first.next;
    35         return temp;
    36     }
    37     
    38     public void insertLast(long d)
    39     {
    40         LinkLast newLink = new LinkLast(d);
    41         if(isEmpty())
    42         {
    43             first = newLink;
    44         }else
    45         {
    46             last.next = newLink;
    47         }
    48         last = newLink;
    49     }
    50     
    51     public void displayLast()
    52     {
    53         System.out.print("List (first-->last):");
    54         LinkLast current = first;
    55         while(current!=null)
    56         {
    57             current.display();
    58             current = current.next;
    59         }
    60         System.out.println();
    61     }
    62 }
    63 class LinkLast
    64 {
    65     public long dData;
    66     public LinkLast next;
    67     
    68     public LinkLast(long dd)
    69     {
    70         dData = dd;
    71     }
    72     
    73     public void display()
    74     {
    75         System.out.print(dData+" ");
    76     }
    77 }
    78 
    79 class FirstLastApp
    80 {
    81     public static void main(String[] args)
    82     {
    83         FirstLastList theList = new FirstLastList();
    84         theList.insertFirst(22);
    85         theList.insertFirst(44);
    86         theList.insertFirst(66);
    87         
    88         theList.insertLast(11);
    89         theList.insertLast(33);
    90         theList.insertLast(55);
    91         
    92         theList.displayLast();
    93         theList.deleteFirst();
    94         theList.deleteFirst();
    95         
    96         theList.displayLast();
    97     }
    98 }
  • 相关阅读:
    这个帖子主要总结数据库备份方面的问题
    Visual C#.Net 网络程序开发Socket篇
    数据库设计说明书参考模板
    用Visual C#开发WinForm的应用程序
    在ASP.NET页中读取文本文件
    如何通过 SQL Server 链接服务器和分布式查询使用 Excel
    ER概念模型
    SQL Server 存储过程的分页方案比拼
    读出某一个目录的文件和文件夹
    Linux中的定时任务简单操作实例
  • 原文地址:https://www.cnblogs.com/speaklessdomore/p/3674732.html
Copyright © 2020-2023  润新知