Skip to content

Instantly share code, notes, and snippets.

@ronalddas
Last active November 17, 2015 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalddas/48bf833a460175ff9b51 to your computer and use it in GitHub Desktop.
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
#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