Removing Duplicates from given Array

Category:

//PROGRAM to Remove Duplicates from a array using pointers
#include < iomanip >
#include < iostream >
using namespace std;
void main()
{
short *arr,size,*ptr1,*ptr2,*end,*new_size,sv;
cout << "Enter the Size of the Array below 20:: ";
cin>>size;
ptr1=arr=new short[size];
end=arr+size;
cout << endl << "Input the values" << endl;
while(ptr1
{
cin>>*ptr1++;
}
ptr1=arr;
new_size=ptr1+1;
//loop to remove duplicates
while(++ptr1 < end)
{
*new_size=sv=*ptr1;
ptr2=arr;
while(sv!=*ptr2)
ptr2++;
if(ptr2==new_size)
new_size++;
}
size=new_size-arr;
end=arr+size;
ptr1=arr;
cout << setw(10) << "Subscript" << "      " << "Values" << endl;
while(ptr1
{
cout << setw(5) << ptr1-arr << "      " << *ptr1 << endl;
ptr1++;
}
system("pause");
}

Comments (0)

Post a Comment