interface Queue2 {
public boolean isEmpty();
public Object getFrontElement();
public Object getRearElement();
public void put(Object theObject);
public Object remove();
}
public boolean isEmpty();
public Object getFrontElement();
public Object getRearElement();
public void put(Object theObject);
public Object remove();
}
class ChainNode {
Object element;
ChainNode next;
Object element;
ChainNode next;
ChainNode() {}
ChainNode(Object element)
{this.element = element;}
ChainNode(Object element, ChainNode next)
{this.element = element; this.next = next;}
}
{this.element = element; this.next = next;}
}
class LinkedQueue implements Queue2 {
protected ChainNode front;
protected ChainNode rear;
protected ChainNode front;
protected ChainNode rear;
public LinkedQueue() {
// the default initial value of front is null
}
// the default initial value of front is null
}
public boolean isEmpty() {
return front == null;
}
return front == null;
}
public Object getFrontElement() {
if (isEmpty()) return null;
else return front.element;
}
public Object getRearElement() {
if (isEmpty()) return null;
else return rear.element;
}
public void put(Object theElement) {
// create a node for theElement
ChainNode p = new ChainNode(theElement, null);
// create a node for theElement
ChainNode p = new ChainNode(theElement, null);
// append p to the chain
if (front == null)
front = p; // empty queue
else
rear.next = p; // nonempty queue
rear = p; //최초인 경우 f,r이 null이 아니면서 같다.
}
if (front == null)
front = p; // empty queue
else
rear.next = p; // nonempty queue
rear = p; //최초인 경우 f,r이 null이 아니면서 같다.
}
public Object remove() {
if (isEmpty()) return null;
Object frontElement = front.element;
front = front.next;
if (isEmpty())
rear = null; // enable garbage collection
return frontElement;
}
public String toString() {
StringBuffer sb = new StringBuffer("[");
ChainNode p = front;
if (isEmpty()) return null;
Object frontElement = front.element;
front = front.next;
if (isEmpty())
rear = null; // enable garbage collection
return frontElement;
}
public String toString() {
StringBuffer sb = new StringBuffer("[");
ChainNode p = front;
do {
if (p.element == null) sb.append("null");
else sb.append(" " + p.element.toString());
p = p.next;
if (p != null) sb.append(",");
} while (p != null);
sb.append(" ]");
return sb.toString();
}
}
if (p.element == null) sb.append("null");
else sb.append(" " + p.element.toString());
p = p.next;
if (p != null) sb.append(",");
} while (p != null);
sb.append(" ]");
return sb.toString();
}
}
public class LinkedQueueTest{
public static void main (String[] args) {
public static void main (String[] args) {
LinkedQueue q = new LinkedQueue();
q.put(new String("aaaa"));
q.put(new String("bbbb"));
q.put(new String("cccc"));
System.out.println("a,b,c 삽입후...");
System.out.println("front : " + q.getFrontElement());
System.out.println("rear : " + q.getRearElement());
System.out.println(q);
q.remove();
System.out.println("aaaa 삭제후...");
System.out.println("front : " + q.getFrontElement());
System.out.println("rear : " + q.getRearElement());
System.out.println(q);
}
}
System.out.println("aaaa 삭제후...");
System.out.println("front : " + q.getFrontElement());
System.out.println("rear : " + q.getRearElement());
System.out.println(q);
}
}
오라클자바커뮤니티교육센터, 개발자전문교육, 개인80%환급
www.oraclejavacommunity.com평일주간(9:30~18:10) 개강
(7/07)[기업100%환급]C#4.0,WinForm,ADO.NET프로그래밍
(7/07)[기업100%환급]Spring ,MyBatis,Hibernate실무과정
(7/07)[기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
(7/07)[채용예정교육]오라클자바개발잘하는신입뽑기프로젝트,교육전취업확정
(7/14)[기업100%환급]SQL기초에서 Schema Object까지
(7/14)[기업100%환급]PL/SQL,ORACLE HINT,TUNING
(7/14)[기업100%환급]안드로이드개발자과정
평일야간(19:00~21:50) 개강
(7/01)닷넷(C#,Network,ADO.NET,ASP.NET)마스터과정
(7/02)Spring3.X, MyBatis, Hibernate실무과정
(7/03)웹퍼블리싱 마스터
(7/10)JAVA,Network&WEB&Framework(자바기초에서웹스프링까지)
(7/15)SQL기초에서실무까지
(7/15)안드로이드개발자과정
(7/15)MyBatis3.X, Hibernate4.X ORM실무과정
(7/22)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
주말(10:00~17:50) 개강
(7/05)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
(7/05)SQL초보에서 Schema Object까지
(7/12)MyBatis3.X, Hibernate4.X ORM실무과정
(7/12)개발자를위한PLSQL,SQL튜닝,힌트
(7/13)C#,ASP.NET마스터
(7/19)Spring3.X, MyBatis, Hibernate실무과정
(7/19)웹퍼블리싱 마스터
(7/19)안드로이드개발자과정
주말저녁(18:30~22:20) 개강
(7/19)JAVA,Network&WEB&Framework
(8/09)SQL기초에서실무까지
댓글 없음:
댓글 쓰기