looking for some solutions? You are welcome.

SOLVED: why do i keep getting errors in my selection sort algorithm

Steven Anderson:

so based on my lectures, book and what I found online my code is proper but I keep getting the same errors no matter what I do. it has become quite discouraging any help would be awesome.

public class OrderedArrayList extends UnorderedArrayList
{

public OrderedArrayList(int size)
{
      super(size);
}

public OrderedArrayList()
{
    super();
}

    //Copy constructor
public OrderedArrayList(OrderedArrayList otherList)
{
    super(otherList);
 }

public void sort()
{// start sort
int min;
for (int i = 0; i < list.length; i++) 
{
    min = i;
    for (int j = i + 1; j < list.length; j++)
     {
        if (list[j] < list[min]) 
        {
            min = j;

        }
     }
    if (min != i)
     {
        final int temp = list[i];
        list[i] = list[min];
        list[min] = temp;
     }
    System.out.println(list[i]);//  print in ascending order  
    }


 }// end sort

}

Here is the error:

 ----jGRASP exec: javac -g OrderedArrayList.java
  OrderedArrayList.java:29: error: bad operand types for binary operator '<'
        if (list[j] < list[min]) 
                    ^
  first type:  DataElement
 second type: DataElement
 OrderedArrayList.java:37: error: incompatible types: DataElement 
 cannot be converted to int
        final int temp = list[i];
                             ^
  OrderedArrayList.java:39: error: incompatible types: 
  int cannot be converted      to DataElement
        list[min] = temp;
                    ^
   3 errors

no matter what data type I write it for integer string I always get the same errors every time. this lab requires it to be DataElement.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent