public class DLNode {
public int Element;
public DLNode left;
public DLNode right;
}
You may NOT use Javas built-in data structure libraries, like java.util.LinkedList, in this homework. All
data structure implementations should be your own or those taken from lectures. You can not use stack
or queue in your implementations.
public void SquashL(); // SquashL takes the linked list and trace the
contiguous blocks in the list. After initiating the method, it changes the
linked list into the list such that there are tuples: the element and number
of occurrence in the list.
For example, if the list is [1 2 3 3 3 3 2 2 2 2 1 2 2 3 2], after initiating
the method the link list converts to: [1 1 2 1 3 4 2 4 1 1 2 2 3 1 2 1]
--- Update ---
public void SquashL() {
DLNode dummy=head; //ı want to use just lınk of head so ı dont create new node ı use lınk of ıt ın dummy
//starting dummy
int b=1;//what ever *element ıs at least it has 1 times in list so we r starting fom "
int a = 0; //for getting element of nodes
for(int i=0;i<numElements;i++){
dummy.Element=a;//listemin başlangıç node u
DLNode dummy1=head; // hangi node oldugu
DLNode howmuch = new DLNode();//araya koyacagım
if(a==dummy1.right.Element){
while(dummy1.right.Element==a){ //checling how many time this element repating
b++;// ı get the number here
numElements--;// my size wıll be decrease becasue ı ll elımınate repeating elements
dummy1=dummy1.right; // for checking nextnode
}
howmuch.Element=b;
howmuch.right=dummy1;
howmuch.left=dummy;
howmuch=dummy.right;
dummy1.left=howmuch;
numElements++;
}
else{
DLNode one = new DLNode();
one.right=dummy.right;
one.left=dummy;
dummy.right=one;
one.right.left=one;
one.Element=1;
numElements++;
}
for(int t=0;t<2;t++)//hiç değişmeyen headımden 2 2 kayıcam buyuk for a gore sıradakı eleman için
dummy=head.right;
}
}
--- Update ---
plss HELP MEE I M STUCK IN THIS METHODDDD