´äÀÌ µÉ·±Áö..


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :À§¼ºÇõ 2000³â 5¿ù 05ÀÏ 23:13:37

In Reply to: int Çü StackÁ» ¸¸µé¾î ÁÖ¼¼¿ä.. posted by µµ¿òÁֽǺÐ.. on 2000³â 5¿ù 05ÀÏ 21:00:14:

public class ExIntStack
{
private Node first;
class Node
{
private int data;
private Node next;
public Node(int input)
{
data = input;
next = null;
}
public void setNext(Node nextNode)
{
next = nextNode;
}
public int getData()
{
return data;
}
public Node getNextNode()
{
return next;
}

}


public void push(int data)
{
if(!isEmpty()){
Node newNode = new Node(data) ;
newNode.setNext(first);
first = newNode;
}
else{
first = new Node(data);
}
}

public Node pop()
{
if(isEmpty())
return null;
else{
Node temp = new Node(first.getData());
first = first.getNextNode();
return temp;
}
}

public boolean isEmpty()
{
if(first==null)
return true;
else
return false;
}

public void printStack(Node node)
{
if(node==null)
return;
printStack(node.getNextNode());
System.err.println(" "+node.getData());
}
public Node getTop()
{
return first;
}

public static void main(String [] args)
{
ExIntStack ex = new ExIntStack();
ex.push(5);
ex.push(6);
ex.printStack(ex.getTop());
Node data = ex.pop();
if(data!=null)
System.err.println(" " + data.getData());
data = ex.pop();
if(data!=null)
System.err.println(" " + data.getData());
data = ex.pop();
if(data!=null)
System.err.println(" " + data.getData());



}


}


// ÁöÁ®ºÐÇÑ programÀÌ µÈ°Í °°½À´Ï´Ù Á¦ ³ª¸§´ë·Î ±ÞÇÏ°Ô ÀÛ¼ºÇÑ programÀ̶ó¼­.. ÀÚ½ÅÀº ¾øÁö¸¸ µÇ¿òÀÌ µÇ¸é ÁÁ°Ú½À´Ï´Ù. java¿¡¼­´Â pointer°¡ ¾ø°í ¸ðµç Object¿¡ ´ëÇؼ­ call-by-reference·Î µÇ±â ¶§¹®¿¡ popÇÒ¶§ »õ·Î¿î node ¸¦ ¸¸µé¾î¼­ return ÇØ ÁÖ¾î¾ß µÉ µí ÇÕ´Ï´Ù. ¶ÇÇÑ data¸¸ return ÇÒ·Á¸é ÁÁÀºµ¥ error¸¦ check ÇÒ ¼ö °¡ ¾øÁÒ ±×·¡¼­ Node ¸¦ return Çϵµ·Ï ÇÏ¿´½À´Ï´Ù. return µÈ node°¡ null ÀÌ¸é ´õÀÌ»ó ½ºÅÿ¡ node°¡ ¾øÀ¸´Ï±î¿ä ¸¸¾à¿¡ data¸¸ return ÇÏ°í ½ÍÀ¸½Ã´Ù¸é exceptionÀ» ¸¸µé¾î¼Å error¸¦ check Çϵµ·Ï ¸¸µå½Ã¸é µÉ µí ÇÕ´Ï´Ù. (Àß ¸ð¸£½Ã°Ú´Ù¸é ¸ÞÀÏ ÁÖ¼¼¿ä



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]