java - Remove minimum value from linkedlist -


i need remove smallest element value linked list.

{8,4,7,2,9,4,5,3}  

becomes:

{8,4,7,9,4,5,3} 

i wrote :

public void removemin() {     t min = list.getinfo();     (int = 0; < 7; i++) {         if (list.getlink() < min)             min = (t) list.getlink();         else             continue;     } }  

you can :

public void removemin() {    int nbelements = list.size()    int lowervalueindex = 0    (i = 0; < nbelements; i++)    {       if(list.get(i) < list.get(lowervalueindex)       {          lowervalueindex = i;       }    }    list.remove(lowervalueindex); } 

first initializethe lowest value first element. @ each element, compare value lower 1 find. if new lower, take new lowervalueindex. @ end have remove lowest element founded. carefull, solution, data must comparable directly


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -