Skip to main content

Posts

Featured

Bubble sort using C++

 #include <iostream> using namespace std; int main() { int arr[]={10,20,30,40,50,60,70}; int flag=0; int n=sizeof(arr)/sizeof(arr[0]); int temp; for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1 - i; j++) { if (arr[j] > arr[j+1]) { temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; flag=1; } } if(flag==0) { cout<<"Values are sorted already \n;";exit(0); } } cout << "Sorted elements:"; for (int i = 0; i < n; i++) { cout << arr[i] << "\t"; } } Output:

Latest posts

Dynamic Memory Allocation in C++: Understanding Arrays with User Input

Doubly Linked List (DLL) Implementation in C++

Singly Linked List in Data Structure using C++

Coding Principles in Programming Languages