This project demonstrates a simple implementation of the bubble sort algorithm in C++ using the Xcode IDE. It sorts an array of integers and prints both the unsorted and sorted versions of the array.
- The main C++ file,
main.cpp
, contains a vector of integers and implements a bubble sort algorithm to sort the elements in ascending order. - The code first displays the unsorted array, performs the sorting, and then outputs the sorted array.
- Bubble Sort Algorithm: A basic sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
- Vector Operations: Uses the C++ STL
vector
for dynamic array handling.
- Xcode: This project was created using Xcode, Apple's IDE for macOS. Ensure you have Xcode installed on your machine.
- C++ Compiler: Xcode includes the necessary C++ compiler.
- Clone or download the project.
- Open the
Bubblesort.xcodeproj
file in Xcode. - Build the project by selecting Product > Build in the Xcode menu or by pressing
Cmd+B
. - Run the project by selecting Product > Run or pressing
Cmd+R
.
The program will print the following to the console:
- The original (unsorted) array.
- The sorted array after the bubble sort is applied.
Original array: 2 5 3 6 9 8 5
Sorted array: 2 3 5 5 6 8 9
This project is open-source and can be freely modified or distributed.