|
| 1 | + |
| 2 | +/******************************************************************************************************* |
| 3 | +/* ___ _ _ _ _ |
| 4 | +/* / _ \ | | (_)| | | | |
| 5 | +/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___ |
| 6 | +/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __| |
| 7 | +/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \ |
| 8 | +/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/ |
| 9 | +/* __/ | |
| 10 | +/* |___/ |
| 11 | +/******************************************************************************************************/ |
| 12 | + |
| 13 | +/************************************************ |
| 14 | +/* Check if numbers in array are consecutive |
| 15 | +/************************************************/ |
| 16 | + |
| 17 | +// Library imports |
| 18 | +#include <iostream> |
| 19 | +using namespace std; |
| 20 | + |
| 21 | +//Prototypes for the algorithms |
| 22 | +bool consecutiveCheckArray(int* arr,int len); |
| 23 | +void someSortingAlgorithm(int* arr,int length); |
| 24 | + |
| 25 | +int main(){ |
| 26 | +// Lines to handle user input go here, be descriptive... |
| 27 | +// use cin, cout |
| 28 | +int arr[] = {5, 2, 3, 1, 4}; |
| 29 | +int arr2[] = {34, 23, 52, 12, 3}; |
| 30 | + |
| 31 | +int arrayLength = sizeof(arr)/sizeof(arr[0]); |
| 32 | +int array2Length = sizeof(arr2)/sizeof(arr2[0]); |
| 33 | + |
| 34 | + |
| 35 | +// Call your algorithms here |
| 36 | +cout<<consecutiveCheckArray(arr, arrayLength)<<endl; |
| 37 | +cout<<consecutiveCheckArray(arr2, array2Length)<<endl; |
| 38 | + |
| 39 | + |
| 40 | +return 0; |
| 41 | +} |
| 42 | + |
| 43 | +/********************************************************** |
| 44 | +/* <consecutiveCheckArray> |
| 45 | +/* |
| 46 | +/* @description : description here |
| 47 | +/* @param : Integer<variable> (Datatype<variable_name>) |
| 48 | +/* @return : datatype (int,float,double etc) |
| 49 | +/* @complexity : Big O notation. (O(n),O(n^2) etc) |
| 50 | +/* @explanation : Detailed description about what the algorithm does |
| 51 | +/* @author : <Your name> @<GitHub handle> (John Doe @johndoe) |
| 52 | +/**********************************************************/ |
| 53 | +bool consecutiveCheckArray(int* arr,int len){ |
| 54 | +// Algorithm content goes here. |
| 55 | +someSortingAlgorithm(arr,len); |
| 56 | + |
| 57 | +int minElement =arr[0]; |
| 58 | + |
| 59 | +for(int i=0;i<len;i++){ |
| 60 | +if(arr[i]==minElement){ |
| 61 | +minElement++; |
| 62 | +} |
| 63 | +else{ |
| 64 | +return false; |
| 65 | +} |
| 66 | +} |
| 67 | +return true; |
| 68 | +} |
| 69 | + |
| 70 | +void someSortingAlgorithm(int* arr,int length){ |
| 71 | + |
| 72 | +for(int i=0;i<length;i++){ |
| 73 | +for(int j=i+1;j<length;j++){ |
| 74 | +if(arr[i]>arr[j]){ |
| 75 | +int temp = arr[i]; |
| 76 | +arr[i] = arr[j]; |
| 77 | +arr[j] = temp; |
| 78 | +} |
| 79 | +} |
| 80 | +} |
| 81 | +} |
0 commit comments