1 28 29 package com.caucho.util; 30 31 34 public class Slist { 35 public Slist next; 36 public Object first; 37 38 public Slist rest() { return next; } 39 public Object value() { return first; } 40 43 public static Slist copy(Slist slist) 44 { 45 if (slist == null) 46 return null; 47 48 Slist head = new Slist(null, slist.first); 49 Slist ptr = head; 50 for (slist = slist.next; slist != null; slist = slist.next) { 51 ptr.next = new Slist(null, slist.first); 52 ptr = ptr.next; 53 } 54 55 return head; 56 } 57 58 61 public static Slist reverse(Slist slist) 62 { 63 if (slist == null) 64 return null; 65 66 Slist prev = null; 67 Slist next = slist.next; 68 while (next != null) { 69 slist.next = prev; 70 71 prev = slist; 72 slist = next; 73 next = next.next; 74 } 75 76 slist.next = prev; 77 78 return slist; 79 } 80 81 84 public static Slist append(Slist a, Slist b) 85 { 86 if (a == null) 87 return b; 88 89 Slist ptr = a; 90 for (; ptr.next != null; ptr = ptr.next) { 91 } 92 93 ptr.next = b; 94 95 return a; 96 } 97 98 101 public static Slist remove(Slist slist, Object object) 102 { 103 if (slist == null) 104 return null; 105 else if (slist.first == object) 106 return slist.next; 107 108 for (Slist ptr = slist; ptr.next != null; ptr = ptr.next) { 109 if (ptr.next.first == object) { 110 ptr.next = ptr.next.next; 111 break; 112 } 113 } 114 115 return slist; 116 } 117 118 121 public Slist(Slist next, Object first) 122 { 123 this.next = next; 124 this.first = first; 125 } 126 } 127 | Popular Tags |