项目作者: EdwinWalela

项目描述 :
C++ Array with sorting methods
高级语言: C++
项目地址: git://github.com/EdwinWalela/superset.git
创建时间: 2019-06-09T19:56:13Z
项目社区:https://github.com/EdwinWalela/superset

开源协议:

下载


SuperArray

C++ Dynamically sized array with sorting methods

Usage

  1. Clone / download the repo
  2. Add SuperArray.h into your working directory
  3. Include the header in your cpp file
  1. #include "SuperArray.h"

Features

  • Dynamically sized
  • Bubble Sort (+ verbose)
  • Merge Sort
  • Reverse function
  • Union
  • Binary Search ( exists( ) method )

TODO

  • Merge Sort (Verbose)
  • Exception Handling ( print( ) method )
  • Intersection
  • Quick Sort
  • Radix Sort
  • Selection Sort
  • Search Algorithims …

Usage

Initialization

The SuperArray can be initialized with a size(optional)

  1. SuperArray<int> arr(5);
  2. SuperArray<int> arr;

Utility Methods

  1. SuperArray<int> arr;
  2. for(int i = 0; i < 5; i++){
  3. arr.push(i); // Add elements to the SuperArray
  4. }
  5. // Output contents of the SuperArray
  6. arr.print(); // [0,1,2,3,4]
  7. // print method can be overloaded by providing limits
  8. int mid = arr.length()/2;
  9. arr.print(mid,arr.length()); // [2,3,4]
  10. // Get length of the SuperArray
  11. arr.length(); // 5

Reverse

  1. // Reverse SuperArray
  2. arr.reverse(); // [4,3,2,1,0]
  1. int x = 4;
  2. int size = arr.length();
  3. bool present = arr.exists(x,0,size);
  4. if(present){
  5. std::cout<<x<<" is present in the SuperArray";
  6. }else{
  7. std::cout<<x<<" does not exist in the SuperArray";
  8. }

Set Union

  1. SuperArray<int> arr1;
  2. for(int i = 0; i < 5; i++){
  3. arr1.push(i);
  4. }
  5. // [0,1,2,3,4]
  6. SuperArray<int> arr2;
  7. for(int i = 5; i < 10; i++){
  8. arr.push(i);
  9. }
  10. // [5,6,7,8,9]
  11. SuperArray<int> setUnion = arr1.setUnion(arr2);
  12. join.print();
  13. // [0,1,2,3,4,5,6,7,8,9]

Sorting Methods

The SuperArray has 4 modes for each sorting algorigthim

  1. Ascending (Asc)
  2. Ascending Verbose (AscV)
  3. Descending (Desc)
  4. Descending Verbose (DescV)

The Verbose mode provides output at each step/pass of the algorithim

1. Bubble Sort

  1. SuperArray<int> arr;
  2. for(int i = 0; i < 5; i++){
  3. arr.push(i);
  4. }
  5. // arr = [ 0 , 1 , 2 , 3 , 4 ]
  6. arr.bubbleSortDesc();
  7. // arr = [ 4 , 3 , 2 , 1 , 0 ]

Verbose Mode

This will print each pass of the bubble sort algorithim

  1. SuperArray<int> arr;
  2. for(int i = 0; i < 5; i++){
  3. arr.push(i);
  4. }
  5. arr.bubbleSortDescV();
  6. /*
  7. Output:
  8. pass(1): 1 2 3 4 0
  9. pass(2): 2 3 4 1 0
  10. pass(3): 3 4 2 1 0
  11. pass(4): 4 3 2 1 0
  12. */