Java代码  

  1. package 串;   
  2.   
  3. public class StringNode {  //  节点类 结构   
  4.   public char data;   
  5.   public StringNode next;   
  6.      
  7.   public StringNode(char c){   
  8.       data = c;   
  9.       next = null;   
  10.   }   
  11.       
  12.   public StringNode(){   
  13.       this('?');   
  14.   }   
  15. }   
  16.   
  17. public class String2 {        //链式存储     实现了部分函数   
  18.    StringNode head,rear;   
  19.    int number=0;   
  20.       
  21.       
  22.       
  23.    public String2(){   
  24.        head = rear = null;   
  25.        number = 0;   
  26.    }   
  27.       
  28.    public String2(char c){   
  29.        head = new StringNode(c);   
  30.        number = 1;   
  31.    }   
  32.       
  33.    public int length2(){   
  34.        return number;   
  35.    }   
  36.       
  37.    public void concat2(char c){   
  38.        StringNode p,q;   
  39.        if(this.head ==null){   
  40.            head = new StringNode(c);   
  41.            this.rear = head;   
  42.        }else{   
  43.            q = new StringNode(c);   
  44.            this.rear.next = q;   
  45.            this.rear = q;   
  46.        }   
  47.        number++;   
  48.    }   
  49.       
  50.    public void concat2(String2 str){   
  51.        StringNode q = str.head;   
  52.        while(q!=null){   
  53.            this.concat2(q.data);   
  54.            q = q.next;   
  55.        }   
  56.    }   
  57.       
  58.       
  59. }