ARBA MINCH
INSTITUTE OF TECHNOLOGY
UNIVERSITY
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;
}
1
Mulatie Kindie
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;
}
1
Mulatie Kindie
DATA structure and algorithm INDIVIDUAL ASSIGNMENT
Insertion sorting on my editor and word format #include <iostream>
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;
}
1
Mulatie Kindie