Beispiel #1
0
 /**
  * Creates binary tree from the linked list.
  *
  * @param linkedList    Orderer ByteData as linked list
  */
 public void createBinaryTreeFromLinkedList(ByteDataLinkedList linkedList)
 {
     linkedList.startIteration();
     while (linkedList.checkObject() != null)
     {
         this.root = new ByteData((byte)0);
         ByteData left  = linkedList.nextObject();
         ByteData right = linkedList.nextObject();
         this.root.setLeftChild(left);
         this.root.setRightChild(right);
         left.setParent(this.root);
         right.setParent(this.root);
         this.root.setCount(left.getCount() + right.getCount());
         linkedList.add(this.root);
     }
 }
Beispiel #2
0
            public void nextByteDataIsReturnedOk()
            {
                this.byteDataLinkedList.add(this.byteData2);
                byteDataLinkedList.startIteration();
                Assert.Equal(null, byteDataLinkedList.checkObject());
                this.byteDataLinkedList.add(this.byteData4);
                byteDataLinkedList.startIteration();
                Assert.Equal(this.byteDataLinkedList.getFirst(), byteDataLinkedList.checkObject());

                ByteData[] byteDataList = new ByteData[3];
                byteDataList[0] = this.byteData3;
                byteDataList[1] = this.byteData0;
                byteDataList[2] = this.byteData1;
                this.byteDataLinkedList.addArray(byteDataList);
                byteDataLinkedList.startIteration();

                ByteData current = byteDataLinkedList.nextObject();

                Assert.Equal(this.byteData1, current);
                Assert.Equal(byteDataLinkedList.getFirst(), current.getPrevious());
                Assert.Equal(this.byteData2, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData2, current);
                Assert.Equal(this.byteData1, current.getPrevious());
                Assert.Equal(this.byteData3, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData3, current);
                Assert.Equal(this.byteData2, current.getPrevious());
                Assert.Equal(this.byteData4, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData4, current);
                Assert.Equal(this.byteData3, current.getPrevious());
                Assert.Equal(byteDataLinkedList.getLast(), current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(null, current);
            }