File: java.util.Stack

package info (click to toggle)
bock 0.20.2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,228 kB
  • ctags: 1,370
  • sloc: ansic: 7,367; java: 5,553; yacc: 963; lex: 392; makefile: 243; sh: 90; perl: 42
file content (51 lines) | stat: -rw-r--r-- 930 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// java.util.Stack -- an implementation of the Java Language Spec sec 21.12
// Written by Charles Briscoe-Smith; refer to the file LEGAL for details.

package java.util;

public class Stack extends Vector {

	// PUBLIC INTERFACE
	public Object push(Object item)
	{
		addElement(item);
		// FIXME: what should this return??
		return item;
	}

	public synchronized Object pop() throws EmptyStackException
	{
		if (size()>0) {
			Object o=lastElement();
			removeElementAt(size()-1);
			return o;
		} else {
			throw new EmptyStackException();
		}
	}

	public Object peek() throws EmptyStackException
	{
		try {
			return lastElement();
		} catch (NoSuchElementException e) {
			throw new EmptyStackException();
		}
	}

	public boolean empty()
	{
		return isEmpty();
	}

	public int search(Object o)
	{
		int pos=lastIndexOf(o);
		if (pos==-1)
			/// FIXME: what should this return??
			return -1;
		else
			return size()-pos;
	}

}