0% found this document useful (0 votes)
14 views4 pages

Mulatie Data Structure

The document describes three sorting algorithms implemented by Mulatie Kindie: bubble sort, selection sort, and insertion sort. For each algorithm, the C++ code to implement the sorting on an integer array is provided, along with a main function to test it by inputting array elements, running the sort, and outputting the results.

Uploaded by

Tewodros Derese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Mulatie Data Structure

The document describes three sorting algorithms implemented by Mulatie Kindie: bubble sort, selection sort, and insertion sort. For each algorithm, the C++ code to implement the sorting on an integer array is provided, along with a main function to test it by inputting array elements, running the sort, and outputting the results.

Uploaded by

Tewodros Derese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ARBA MINCH UNIVERSITY

INSTITUTE OF TECHNOLOGY
DEPARTMENT OF SOFTWARE ENGINEERING
DATA structure and algorithm ASSIGNMENT

Name: Mulatie Kindie


ID: NSR/1779/13
Section: B

Submitted to: mister.


Date: June 2023
DATA structure and algorithm INDIVIDUAL ASSIGNMENT #include <iostream>
Bubble sorting on my editor and word format using namespace std;

void bubbleSort(int arr[], int n) {

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

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

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

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp ; }

void printArray(int arr[], int n) {

for (int i = 0; i < n; ++i) {

cout << arr[i] << " ";}

cout << endl;}

int main() {

int size;

cout << "Enter the size of the array: ";

cin >> size;

int arr[size];

cout << "Enter the elements of the array: ";

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

cin >> arr[i]; }

bubbleSort(arr, size);

cout << "Array after sorting: ";

printArray(arr, size);

return 0;

Mulatie Kindie 1
DATA structure and algorithm INDIVIDUAL ASSIGNMENT

#include <iostream>

Selection sorting on my editor and word format using namespace std;

void selectionSort(int arr[], int size) {

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

int minIndex = i;

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

if (arr[j] < arr[minIndex]) {

minIndex = j;

int temp = arr[i];

arr[i] = arr[minIndex];

arr[minIndex] = temp;

int main() {

int size;

cout << "Enter the size of the array: ";

cin >> size;

int arr[size];

cout << "Enter the elements of the array:\n";

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

cin >> arr[i]; }

selectionSort(arr, size);

cout << "Sorted array: ";

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

cout << arr[i] << " "; }

cout << endl;

return 0;

Mulatie Kindie 2
DATA structure and algorithm INDIVIDUAL ASSIGNMENT

#include <iostream>
Insertion sorting on my editor and word format
using namespace std;

void insertionSort(int arr[], int size) {

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

int key = arr[i];

int j = i - 1;

while (j >= 0 && arr[j] > key) {

arr[j + 1] = arr[j];

j--;

arr[j + 1] = key;

int main() {

int size;

cout << "Enter the size of the array: ";

cin >> size;

int arr[size];

cout << "Enter the elements of the array: ";

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

cin >> arr[i];

insertionSort(arr, size);

cout << "Sorted array: ";

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

cout << arr[i] << " ";

return 0;

Mulatie Kindie 3

You might also like