write a progam for bubble sort using file read nd write?

write a progam for bubble sort using file read nd write?

hi, please give the code

View Answers

November 2, 2011 at 3:33 PM

import java.io.*;
import java.util.*;
public class FilebubbleSortExample{
  public static void main(String a[])throws Exception{
  ArrayList<Integer> list=new ArrayList<Integer>();
  BufferedReader br=new BufferedReader(new FileReader("num.txt"));
  BufferedWriter bw=new BufferedWriter(new FileWriter("new.txt",true));
  String st="";
  while((st=br.readLine())!=null){
      list.add(new Integer(Integer.parseInt(st)));
  }
  int i;
  int array[] = toIntArray(list);
  System.out.println("Values Before the sort:\n");
  for(i = 0; i < array.length; i++)
  System.out.print(array[i]+"  ");
  System.out.println();
  bubble_srt(array, array.length);
  System.out.print("Values after the sort:\n");
  for(i = 0; i <array.length; i++){
      System.out.print(array[i]+"  ");
      bw.write(Integer.toString(array[i]));
      bw.newLine();
  }
  bw.close();
  System.out.println();
  }
  public static void bubble_srt( int a[], int n ){
  int i, j,t=0;
  for(i = 0; i < n; i++){
          for(j = 1; j < (n-i); j++){
              if(a[j-1] > a[j]){
                  t = a[j-1];
                  a[j-1]=a[j];
                  a[j]=t;
              }
          }
      }
   }
   static int[] toIntArray(List<Integer> integerList) {
            int[] intArray = new int[integerList.size()];
            for (int i = 0; i < integerList.size(); i++) {
             intArray[i] = integerList.get(i);
            }
            return intArray;
       }
 }









Related Tutorials/Questions & Answers:
write a progam for bubble sort using file read nd write?
read and write a file using javascript
Advertisements
bubble sort
how to read and write an xml file using java
To read & write a excel file using the core java
bubble sort
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
Read and write file
bubble sort - Java Beginners
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
Java file read write operation
Bidirectional Bubble Sort in Java
Need help in constructing bubble sort
read/write to Windows Registry using Java
Write to a file
How to write to file using FileOutputStream
write a javascript progam to implement functions in html
How to write to file using FileWriter
Bubble Sorting in Java
Java program to read a text file and write to another file
Bubble Sort in Java
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file
upload a file and write it in JSP using servlet
Sort file data and write into another file
Read Write
how to read file using InputStreamReader in java
read from file and store using hash map
How to Read a file line by line using BufferedReader?
read XML file and display it using java servlets
Bubble Sort Program in Java
Java write file
Java Write To File BufferedWriter
how to use Excel Templet to write excel file using java.
how to use Excel Template to write excel file using java
how to write greater than symbol in a file using java
Write Hello in the pdf file
How to read properties file in Python using configparser?
How to read the data in text file seperated by by ',' in java using IO Operations
How to Read file line by line in Java program
How to Retrieve Data from the database and write into excel file using Java
Java Write To File FileWriter
Java Read .doc file using POI library
Read data from excel file and update database using jsp
how to read file line by line using filereader in java
tow method to read and write .
read a file
Java Write To File From String
file read

Ads