1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <stdio.h>
#include "simpio.h"
int removedup (int inpArray[], int inpArraySize, int outArray[], int arr[]);
int main()
{
int size=5;
int inpArray[size], inpArraySize, outArray[size], arr[size];
removedup(inpArray, inpArraySize, outArray, arr);
getchar();
return 0;
}
int removedup (int inpArray[], int inpArraySize, int outArray[], int arr[])
{
int j = 0;
int x, k, i;
int count = 0;
int flag, temp;
printf("Enter the size of inpArray\n");
inpArraySize=GetInteger();
printf("Enter %d integers\n", inpArraySize);
for (x=0; x<inpArraySize; x++)
{
inpArray[x]=GetInteger();
}
for(i = 1; (i <= inpArraySize) && flag; i++)
{
flag = 0;
for (j=0; j < (inpArraySize -1); j++)
{
if (inpArray[j+1] < inpArray[j]) // ascending order simply changes to <
{
temp = inpArray[j]; // swap elements
inpArray[j] = inpArray[j+1];
inpArray[j+1] = temp;
flag = 1; // indicates that a swap occurred.
}
}
}
printf("These are the original values of 'inpArray[] sorted from least to greatest\n");
for (x=0; x<inpArraySize; x++)
{
printf("%d ", inpArray[x]);
}
printf("\n\n");
printf("In addition, these are the values of the new array without duplicates\n");
for (x=0; x<inpArraySize; x++)
{
if (inpArray[x] != inpArray[x+1])
{
outArray[j]=inpArray[x];
j+=1;
}
}
j-=1;
for (i=0; i<inpArraySize-j; i++)
{
printf("%d ", outArray[i]);
}
return 0;
}
|