İnsertion Sort

9 views
Skip to first unread message

Müge İyidir

unread,
Dec 14, 2009, 5:34:43 PM12/14/09
to Fırat Üniversitesi Bilgisayar Mühendisliği
public class liste implements queue{
node temphead=null;
node head=null;
int size=0;

public liste() {

}
public void enqueue(int element) {
node x=new node();

x.element=element;
size++;
if(head==null){
head=x;
}
else{
node ara=head;
while(ara.next!=null){
ara=ara.next;
}
ara.next=x;
}
}
public int size() {
return size;
}

public boolean isEmpty() {
return head==null;
}


public node dequeu()throws RuntimeException {
if(head == null)throw new RuntimeException("Dizi boÅŸ");
node x;
x=head;
head=x.next;
x.next=null;
size--;
return x;

}

public void yaz(){
node ara=head;
while(ara.next!=null){
System.out.println("Gelen rastgele sayı" + ara.element);
ara=ara.next;

}
}
public void sirala(){
temphead=null;
while(!isEmpty()){
node temp=dequeu();
if(temphead==null){
temphead=new node();
temphead.next=temp;
System.out.println("Birinci sayı atandi");
}
else{

node ara=temphead;
while (ara.next!
=null&&temp.element>ara.next.element) {
ara=ara.next;

}

if(ara.next!=null)
temp.next=ara.next;
//araya eklendi
ara.next=temp;

}
}
node ara=temphead;
System.out.println("siralandi=");



}


public node head() throws RuntimeException {
if(head == null)throw new RuntimeException("Dizi boş");


return head;
}
public static void main(String[] args) throws
QueueEmptyException {
liste b=new liste();

}







}
Reply all
Reply to author
Forward
0 new messages