function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sathish Kumar 241Sathish Kumar 241 

Help needed in repeat element

Hi,

I have implemented Bubble sort on array of integers. Which also prints iteration details.
I want to print that iteration details on vf page. Below is my apex code and vf page.
vf page

<apex:page controller="bubbleSort1">
  <apex:form >

  
  
  <apex:pageBlock >
  Enter Number
  :<apex:inputtext value="{!userInput}"/>
       <apex:pageblockbuttons >
           <apex:commandbutton value="Display" action="{!display}"/>
               </apex:pageblockbuttons>
      <apex:pageBlockSection >
          <apex:outputLabel >These are the sorted values</apex:outputLabel>
        <!--  <apex:inputText value="{!values}"/> -->
      </apex:pageBlockSection>
      <apex:pageBlockSection >
          <apex:pageBlockTable value="{!bubbleSortMethod}" var="a">
              <apex:column value="{!a}"/>
          </apex:pageBlockTable>
          
      </apex:pageBlockSection>
  
  </apex:pageBlock>
       </apex:form> 
</apex:page>

Controller
public class bubbleSort1 {
      // public list<integer> values {get;set;}
    public String userInput {get;set;}
    public List<Integer> values = new List<Integer>{12,45,89,78,65,23};
    public list<Integer> getbubbleSortMethod(){
    
      // values = new list<integer>();
      //  values.add(5);
      //  values.add(8);
        integer iterationsize = values.size();
        integer temp = 0;
        integer temp5;
        boolean b;
        integer count=0;
        for(integer i=0; i < iterationsize; i++){
            for(integer j=1; j < (iterationsize-i); j++){
                temp5=values[j-1];
                if(values[j-1] > values[j]){
                    //swap the elements!
                    temp = values[j-1];
                    values[j-1] = values[j];
                    values[j] = temp;
                }
                if(values[j-1] != temp5){
                b=true;
                system.debug('swaped result is'+ values);
                    
                }
                if(b==false)
                count=count+1;
            }
        }
     
        System.debug('values ' + values);
        system.debug('No of iterations are'+ values.size());
        return values;
    }
            public void display(){
                system.debug('User input...' +userInput);
                List<String> temp = userInput.split(',');
                for(String s : temp){
                    values.add(Integer.valueOf(s));
                }
                
               
            
            }
    
}


Thanks in advance
bob_buzzardbob_buzzard
What problem are you encountering?