Last active
November 17, 2015 05:11
-
-
Save ronalddas/48bf833a460175ff9b51 to your computer and use it in GitHub Desktop.
A program to input, display and remove duplicates from an integer array using the concept of OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class CLASSONE | |
{ | |
public: | |
void remDup(int a[],int size) | |
{ | |
int i , j , k; | |
for ( i = 0; i < size; i++) | |
{ | |
for ( j = i+1; j < size ; ) | |
{ | |
if (a[i]==a[j]) | |
{ | |
for( k =j ; k < siz; k++) | |
{ | |
//Replaces the value of element by next one | |
a[k]=a[k+1]; | |
} | |
size--; //Reduces size by 1,Important | |
} | |
else | |
j++;//Skips to next number! | |
} | |
} | |
for( i =0 ; i < siz; i++) | |
cout<<a[i]<<endl; | |
} | |
}; | |
int main(void) | |
{ | |
int b[50],n,i,j; | |
cout<<"Enter array size\n"; | |
cin>>n; | |
cout<<"Enter elements \n"; | |
for(i = 0; i < n; i++) | |
cin>>b[i]; | |
cout<<"The array is \n"; | |
for( i = 0 ; i < n; i++) | |
cout<<b[i]<<endl; | |
cout<<"The new array is \n"; | |
CLASSONE objectOne; | |
objectOne.remDup(b,n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment