Skip to main content

C++ Code of Bubble Sort

Bubble sort, often incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order.


Here is the C++ implantation of Bubble sort

#include <iostream>

using namespace std;

int main()
{
    int i,j, n;
    cout<< "How much number you will sort?" << endl;
    cin>>n;
    int a[n];
    for(int x=1; x<=n;x++)
    {
        cout<< "Enter "<< " Number "  << x <<": "  << endl;
        cin>>a[x];

    }
for(int i=1; i<=n;i++)
    for(int j=i+1; j<=n;j++)
        {
        if (a[i]>a[j]){
            int temp;
            temp = a[i];
            a[i]=a[j];
            a[j]=temp;
        }

}

cout<< "Sorted numbers are:" << endl;
for(int x=1; x<=n;x++)
    {
        cout<< a[x] << ", ";

    }

    return 0;
}
Thanks, Jakir Hossain

Comments

  1. please also provide the minimum header files which is suitable whether is will run just by ctype.h or string.h .......................

    ReplyDelete
  2. thanx man.....nicely done....was helpful

    ReplyDelete
  3. thanx man.....nicely done....was helpful

    ReplyDelete
  4. nicely written implementation of bubble sort algorithm but it is missing explanation, if anyone wants explanations then they could find it there:

    http://www.hellgeeks.com/bubble-sort/

    ReplyDelete
  5. Programme work! good job

    ReplyDelete
  6. Programme work! good job

    ReplyDelete
  7. Great blog.
    Thank you for written this blog regarding to core technology.This is very Helpful and informative blog.
    mobile app training institutes
    iphone job oriented course

    ReplyDelete
  8. Thanks for offering us such a useful details. Keep up the great work. You can also check out this awarded Vitamin supplement store for nutritional supplements from leading brands.
    Nutritional Supplements

    ReplyDelete

Post a Comment

Give your valuable Comment...

Popular posts from this blog

Object-Oriented Programming and JAVA Programming Language

  Object-Oriented Programming and:   Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, olymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option. JAVA Programming Language: Object-oriented programming is at the core of Java. In fact, all Java programs are object-oriented, this isn’t an option the way that it is in C++, for example. OOP is so integral to Java that you must understand its basic principles before you can write even simple Java programs. Therefore, this chapter begins with a discussion of the theoretical aspects of OOP.

Compilation Process of a C++ Program

Compiling a C++ program involves a number of steps (most of which are transparent to the user): · First, the C++ preprocessor goes over the program text and carries out theinstructions specified by the preprocessor directives (e.g., #include ). The result is a modified program text which no longer contains any directives. · Then, the C++ compiler translates the program code. The compiler may be a true C++ compiler which generates native (assembly or machine) code, or just a translator which translates the code into C. In the latter case, the resulting C code is then passed through a C compiler to produce native object code. In either case, the outcome may be incomplete due to the program referring to library routines which are not defined as a part of the program. For example, Listing 1.1 refers to the << operator which is actually defined in a separate IO library. · Finally, the linker completes the object code by linking it with the object code of any lib...

Read or input form user in Java using BufferedReader

 BufferedReader use to read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In Java  BufferedReader is a efficient method to read an input. Here given a short example to read a string from user and print it: package palindrome; import java.io.BufferedReader; import java.io.InputStreamReader; public class  inputExample   {     public static void main(String[] args) throws Exception {    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String s = new String();       s =br.readLine();     System.out.println(s);     } }