C++ Array with sorting methods
C++ Dynamically sized array with sorting methods
SuperArray.h
into your working directory
#include "SuperArray.h"
The SuperArray can be initialized with a size(optional)
SuperArray<int> arr(5);
SuperArray<int> arr;
SuperArray<int> arr;
for(int i = 0; i < 5; i++){
arr.push(i); // Add elements to the SuperArray
}
// Output contents of the SuperArray
arr.print(); // [0,1,2,3,4]
// print method can be overloaded by providing limits
int mid = arr.length()/2;
arr.print(mid,arr.length()); // [2,3,4]
// Get length of the SuperArray
arr.length(); // 5
// Reverse SuperArray
arr.reverse(); // [4,3,2,1,0]
int x = 4;
int size = arr.length();
bool present = arr.exists(x,0,size);
if(present){
std::cout<<x<<" is present in the SuperArray";
}else{
std::cout<<x<<" does not exist in the SuperArray";
}
SuperArray<int> arr1;
for(int i = 0; i < 5; i++){
arr1.push(i);
}
// [0,1,2,3,4]
SuperArray<int> arr2;
for(int i = 5; i < 10; i++){
arr.push(i);
}
// [5,6,7,8,9]
SuperArray<int> setUnion = arr1.setUnion(arr2);
join.print();
// [0,1,2,3,4,5,6,7,8,9]
The SuperArray has 4 modes for each sorting algorigthim
The Verbose mode provides output at each step/pass of the algorithim
SuperArray<int> arr;
for(int i = 0; i < 5; i++){
arr.push(i);
}
// arr = [ 0 , 1 , 2 , 3 , 4 ]
arr.bubbleSortDesc();
// arr = [ 4 , 3 , 2 , 1 , 0 ]
This will print each pass of the bubble sort algorithim
SuperArray<int> arr;
for(int i = 0; i < 5; i++){
arr.push(i);
}
arr.bubbleSortDescV();
/*
Output:
pass(1): 1 2 3 4 0
pass(2): 2 3 4 1 0
pass(3): 3 4 2 1 0
pass(4): 4 3 2 1 0
*/