Title: Xref Output
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Output from the Xref program




1:  // This class maintains a Sorted List of WordInfo classes.
2:  // The first criterea of the sort is the Word in WordInfo.
3:  // If classes have the same word, then the line number breaks
4:  // the tie.
5:
6:  // To learn about how to use this class, execute:
7:  //
8:  // java SortedList
9:  //
10: // The main routine will demo how to use this class with a little
11: // example.
12:
13: // Note that SortedList has a toString method that dumps out a
14: // printout of the SortedList contents.
15:
16:
17: public class SortedList
18: {
19:    WordInfo head=null;
20:
21:    // The next routine can be used to obtain the next element in
22:    // the list.  To start at the beginning, pass in a null for the
23:    // one parameter.  When a null is returned, you are at the end
24:    // of the list
25:
26:
27:    public WordInfo next(WordInfo w)
28:    {
29:         if (w == null) return head;
30:         else return w.next;
31:    }
32:
33:    // This routine not only dumps the contents of the SortedList,
34:    // but it also shows you how to create a loop to look at the
35:    // individual objects.
36:
37:
38:    public String toString()
39:    {
40:         WordInfo w ;
41:         StringBuffer sb = new StringBuffer();
42:         for(w=next(null);w != null; w=next(w))
43:         {
44:             sb.append(w+" ");
45:         }
46:         return sb.toString();
47:    }
48:
49:    // The routine allows you to add new items to the Sorted List
50:    // Don't worry about the details about how it works.
51:    // The key thing is that the list is stored in sorted order.
52:
53:    public void add(String word, int line)
54:    {
55:         WordInfo w2Insert = new WordInfo(word,line);
56:         if (head == null)
57:         {
58:             head = w2Insert;
59:             return;
60:         }
61:         int d = head.compareTo(w2Insert);
62:         if (d > 0)
63:         {
64:             w2Insert.next = head;
65:             head = w2Insert;
66:             return;
67:         }
68:
69:         WordInfo w ;
70:         WordInfo wnext;
71:         for(w=head;;w=wnext)
72:         {
73:            wnext = w.next;
74:            if (wnext == null)
75:            {
76:                 w.next = w2Insert;
77:                 return;
78:            }
79:            d = w.compareTo(w2Insert);
80:            if (d==0)
81:            {
82:                 w.count += 1;
83:                 return;
84:            }
85:            int d2 = wnext.compareTo(w2Insert);
86:            if (d2 ==0)
87:            {
88:                 wnext.count += 1;
89:                 return;
90:            }
91:            if (d < 0 && d2 > 0)
92:            {
93:               w2Insert.next=wnext;
94:               w.next=w2Insert;
95:               return;
96:            }
97:
98:         }
99:    }
100:
101:   public static void main(String[] args)
102:   {
103:        SortedList list = new SortedList();
104:        list.add( "zebra",5);
105:        list.add( "melon",5);
106:        list.add( "orange",1);
107:        list.add( "apple",2);
108:        list.add( "belly",3);
109:        list.add( "melon",2);
110:        list.add( "pop",1);
111:        list.add( "melon",2);
112:        list.add( "cat",3);
113:        list.add( "zebra",5);
114:
115:        System.out.println("list="+ list);
116:
117:        // Alternatively, you can create your own loop to
118:        // walk through the SortedList as follows:
119:
120:        WordInfo w, last=null;
121:
122:        for (w=list.next(null); w != null; w = list.next(w))
123:        {
124:            boolean same = w.sameWord(last);
125:            if (same)
126:                System.out.println(w);
127:            else System.out.println("New Word: "+ w);
128:            last = w;
129:        }
130:   }
131:
132:}

*****************************************
           XREF
*****************************************

Alternatively 117
Don       50
If        3
List      1   49
New       127
Note      13
Sorted    1   49
SortedList 8   13  14  17  33
          103 118
String    38  53  101
StringBuffer 41
System    115 126 127
The       2   10  21  49  51
This      1   33
To        6   22
When      23
Word      2   127
WordInfo  1   2   19  27  40
          55  69  70  120
a         1   10  13  22  23
          34
about     6   50
add       49  53  104 105 106
          107 108 109 110 111 112
          113
allows    49
also      34
append    44
apple     107
are       23
args      101
as        118
at        22  23  34
be        21
beginning 22
belly     108
boolean   124
breaks    3
but       34
can       21  117
cat       112
class     1   6   10  17
classes   1   3
compareTo 61  79  85
contents  14  33
count     82  88
create    34  117
criterea  2
d         61  62  79  80  91
d2        85  86  91
demo      10
details   50
dumps     13  33
element   21
else      30  127
end       23
example   11
execute   6
first     2
follows   118
for       22  42  71  122
has       13
have      3
head      19  29  56  58  61
          64  65  71
how       6   10  34  50
if        29  56  62  74  80
          86  91  125
in        2   21  22  51
individual 35
int       53  61  85
is        2   23  51
it        34  50
items     49
java      8
key       51
last      120 124 128
learn     6
line      3   53  55
list      22  24  51  103 104
          105 106 107 108 109 110
          111 112 113 115 122
little    10
look      34
loop      34  117
main      10  101
maintains 1
melon     105 109 111
method    13
new       41  49  55  103
next      21  27  30  42  64
          73  76  93  94  122
not       33
null      19  22  23  29  42
          56  74  120 122
number    3
objects   35
obtain    21
of        1   2   14  24  33
one       23
only      33
orange    106
order     51
out       13  115 126 127
own       117
parameter 23
pass      22
pop       110
println   115 126 127
printout  14
public    17  27  38  53  101
return    29  30  46  59  66
          77  83  89  95
returned  23
routine   10  21  33  49
same      3   124 125
sameWord  124
sb        41  44  46
shows     34
sort      2
sorted    51
start     22
static    101
stored    51
t         50
that      13  51
the       2   3   4   14  21
          22  23  24  33  34  49
          50  51  118
then      3
thing     51
this      6   10
through   118
tie       4
to        6   10  21  34  49
          117
toString  13  38  46
use       6   10
used      21
void      53  101
w         27  29  30  40  42
          44  69  71  73  76  79
          82  94  120 122 124 126
          127 128
w2Insert  55  58  61  64  65
          76  79  85  93  94
walk      118
will      10
with      10
wnext     70  71  73  74  85
          88  93
word      3   53  55
works     50
worry     50
you       23  34  49  117
your      117
zebra     104 113