1. Write an algorithm for the add method that will add at the end of the list instead of the beginning.
2. Modify the algorithm from the previous exercise so that it makes use of a rear reference.我第一个问题已经写出来了,就是不知道对不对. 第2个问题完全没看懂.
Answer 1: addLast(a) {
          a.setNext(null); //make new node a point to null object
          tail.setNext(a); //make old tail node point to new node
          tail = a; //make variable tail point to new node
          size = size + 1;} //increment the node count
希望高手帮助我,在线等!

解决方案 »

  1.   

    第一个是要求实现在list尾部增加记录。
    记录号 加入序号
    1     5
    2     4
    3     3
    4     2
    5     1
    第二个里边的 rear不记得什么意思了。
      

  2.   

      rear 说的是尾指针吧?
      

  3.   

    我觉得楼主第一个方法写的不对吧,1.是让链表尾添加。
    2.是实现尾指针操作,如果实现,链表尾添加就方便多了。
    以前学过c的数据结构都是先定义结构体,这个实现的思想是很简单的,java还真没弄过数据结构。。不知道怎么写