Thread View: cn.bbs.comp.lang.java
1 messages
1 total messages
Started by flysky
Thu, 29 Oct 2009 14:11
����Object�������
Author: flysky
Date: Thu, 29 Oct 2009 14:11
Date: Thu, 29 Oct 2009 14:11
36 lines
2258 bytes
2258 bytes
��̴�ţ�������public Object top()Ϊʲô���ܷ���Object������Eclipse������˵Can't convert from Object to Object;
���public void push(Object element)����Ҳ����ӡ�
Object���������ĸ�����Ϊʲô��������������أ�
package study;
import java.util.LinkedList;
import java.util.*;
//������ʹ��LinkedListʵ��һ����ջ
class LinkedListStack {// ��ջ�ڲ�ʹ��һ��LinkedList�������Ԫ��
private LinkedList data = new LinkedList<String>();
public boolean isEmpty() {
return data.isEmpty();
}
public Object top() {// ȡջ��Ԫ���൱��ȡLinkedList������ͷλ�õ�Ԫ��
return data.getFirst();
}
public void push(Object element) {// ѹ��Ԫ���൱����LinkedList������ͷλ�ò���Ԫ��
data.addFirst(element);
}
public void pop() {// ����Ԫ���൱��ɾ��LinkedList������ͷλ�õ�Ԫ��
data.removeFirst();
}
}
public class LinkedListDemo {
public static void main(String[] args) {
LinkedListStack stack = new LinkedListStack();// ��������ʹ����LinkedListʵ�ֵĶ�ջ���÷�
stack.push("C++");
stack.push("C#");
stack.push("Java");
while (! stack.isEmpty()) {
System.out.println(stack.top());
stack.pop();
}
}
}
--
[1;34m�� ��Դ:�������ʵBBS http://bbs.tju.edu.cn [FROM: 202.113.182.86][m
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads