17-12-2010, 07:51 PM
|
|
|
|
تاريخ التسجيل: Jul 2009
التخصص: IS
نوع الدراسة: إنتظام
المستوى: الثامن
الجنس: أنثى
المشاركات: 272
|
|
"Stack with LinkedList "in Java
السلام عليكم ورحمة الله
ممكن اعرف فين الخطأ في ذا الكود
كود PHP:
public class Link{
private int element;
private Link next;
public Link(){
this(0,null);
}
public Link(int e,Link x){
element=e;
next=x;
}
public int getElement(){
return element;
}
public Link getNext(){
return next;
}
public void setElement(int z){
element=z;
}
public void setNext(Link v){
next=v;
}
}
كود PHP:
/
* @(#)stack_LinkedList.java
*
* stack_LinkedList application
*
* @author
* @version 1.00 2010/12/15
*/
import java.util.*;
public class St1{
private int size;
private Link top;
public St1(){
size=0;
top=null;
}
public boolean isEmpty(){
if (top==null)
return true;
return false;
}
public void push(int e){
Link s=new Link(e,top);
top=s;
size++;
}
public int top(){
if(isEmpty())
return -1;
return top.getElement();
}
public int pop() {
if(isEmpty())
return -1;
int temp=top.getElement();
size--;
return temp;}
public int size(){
return size;
}
}
كود PHP:
/
* @(#)Assig.java
*
* Assig application
*
* @author
* @version 1.00 2010/12/17
*/
public class Assig {
public static void main(String[] args) {
St1 theStack = new St1(); // make new stack
theStack.push(20); // push items onto stack
theStack.push(40);
theStack.push(60);
theStack.push(80);
while(!theStack.isEmpty()) // until it's empty,
{ // delete item from stack
int value = theStack.pop();
System.out.print(value); // display it
System.out.print(" ");
} // end while
System.out.println("");
} // end main()
} // end class StackApp
ليش يطلع لي infinit loop مع انه الشرط سليم
ارجو الافاده
-------------------------------------
|
التعديل الأخير تم بواسطة شمعة مضيئة ; 17-12-2010 الساعة 07:56 PM.
|