0% found this document useful (0 votes)
11 views3 pages

Bubble Sort Algorithm Using Loops: Assignment Programming

This document presents a programming assignment on implementing the Bubble Sort algorithm using loops in C++. It includes the code for the algorithm, functions for sorting and printing an array, and instructions for user input. The assignment was submitted by Waleed Ghaffar from the University of Lahore on March 12, 2025.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Bubble Sort Algorithm Using Loops: Assignment Programming

This document presents a programming assignment on implementing the Bubble Sort algorithm using loops in C++. It includes the code for the algorithm, functions for sorting and printing an array, and instructions for user input. The assignment was submitted by Waleed Ghaffar from the University of Lahore on March 12, 2025.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment Programming

Bubble Sort Algorithm using Loops

Submitted by:

Waleed Ghaffar

Reg. No# 70148780

Dated: 12th March, 2025.

Department of Computer Science

The University of Lahore.


#include <iostream>
using namespace std;

void bubbleSort(int arr[], int size)


{
for (int i = 0; i < size - 1; ++i)
{
for (int j = 0; j < size - i - 1; ++j)
{

if (arr[j] > arr[j + 1])


{
swap(arr[j], arr[j + 1]);
}
}
}
}

void printArray(int arr[], int size)


{
for (int i = 0; i < size; ++i)
{
cout << arr[i] << " ";
}
cout << endl;
}

int main()
{

int size;
cout << "\nEnter the size of the array: ";
cin >> size;
int *arr = new int[size];
cout << "\nEnter the array elements: ";
for (int i=0;i<size;i++)
{
cin>>arr[i];
}
cout << "Unsorted array: ";
printArray(arr, size);
bubbleSort(arr, size);
cout << "Sorted array: ";
printArray(arr, size);
delete[] arr;
return 0;
}

Output:

You might also like