|
| 1 | + |
| 2 | +/******************************************************************************************************* |
| 3 | +/* ___ _ _ _ _ |
| 4 | +/* / _ \ | | (_)| | | | |
| 5 | +/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___ |
| 6 | +/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __| |
| 7 | +/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \ |
| 8 | +/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/ |
| 9 | +/* __/ | |
| 10 | +/* |___/ |
| 11 | +/******************************************************************************************************/ |
| 12 | + |
| 13 | +/*********************************** |
| 14 | +/* Find two repeating elements in an Array |
| 15 | +/***********************************/ |
| 16 | + |
| 17 | +// Library imports |
| 18 | +#include <iostream> |
| 19 | +using namespace std; |
| 20 | + |
| 21 | +//Prototypes for the algorithms |
| 22 | +void repeatingElementsInArray(int* arr,int arrLen); |
| 23 | + |
| 24 | +int main(){ |
| 25 | +// Lines to handle user input go here, be descriptive... |
| 26 | +// use cin, cout |
| 27 | +int testArray[] ={4, 2, 4, 5, 2, 3, 1}; |
| 28 | + |
| 29 | +int arrayLength = sizeof(testArray)/sizeof(testArray[0]); |
| 30 | + |
| 31 | +// Call your algorithms here |
| 32 | +repeatingElementsInArray(testArray,arrayLength); |
| 33 | + |
| 34 | +return 0; |
| 35 | +} |
| 36 | + |
| 37 | +/********************************************************** |
| 38 | +/* <repeatingElementsInArray> |
| 39 | +/* |
| 40 | +/* @description : description here |
| 41 | +/* @param : Integer<variable> (Datatype<variable_name>) |
| 42 | +/* @return : datatype (int,float,double etc) |
| 43 | +/* @complexity : Big O notation. (O(n),O(n^2) etc) |
| 44 | +/* @explanation : Detailed description about what the algorithm does |
| 45 | +/* @author : <Your name> @<GitHub handle> (John Doe @johndoe) |
| 46 | +/**********************************************************/ |
| 47 | +void repeatingElementsInArray(int* arr,int arrLen){ |
| 48 | +// Algorithm content goes here. |
| 49 | +for(int i=0;i<arrLen;i++){ |
| 50 | +for(int j=i+1;j<arrLen;j++){ |
| 51 | +if(arr[i]==arr[j]){ |
| 52 | +cout<<arr[i]<<" "; |
| 53 | +} |
| 54 | +} |
| 55 | +} |
| 56 | +cout<<endl; |
| 57 | +} |
0 commit comments