by Dinesh Thakur Category: array

Algorithm for Removing duplicate elements from Array:

step 1: read y

step 2: create two integer array a[],b[] of size y

step 3: initialize c=0

step 4: repeat through step-6 while c less than a.length

step 5: read a[c]

step 6: c=c+1

step 7: initialize c=0

step 8: repeat through step-11 while c less than a.length

step 9: print a[c]

step 10: print one space

step 11: c=c+1

step 12: initialize t=0

step 13: repeat through step-l8while t less than a.length

step 14: initialize x=t+1

step 15: repeat through step-17 while x less than a.length

step 16: if a[t] equals to a[x] then set a[x]=0

step 17: x=x+1

step 18: t=t+ 1

step 19: set y =0

step 20: initialize c=0

step 21: repeat through step-23 while c less than a.length

step 22: If a[c] not equals to 0 then set b[y]=a[c] and set y=y+1

step 23: c=c+1

step 24: Initialize x=0

step 25: repeat through step-28 while x less than y

step 26: print b[x]

step 27: print one space

step 28: x=x+1

step 29: Exit

Here is the Java Example for removing duplicate elements from Array:

import java.util.Scanner;

public class RemovingDuplicateElements
            public static void main(String args[])
            int c,t,x,y;
            Scanner s=new Scanner(;
            System.out.println("Enter the size of array");
            int a[]=new int[y];
            int b[]=new int[y];
            System.out.println("Enter The Elements of Array");
                 System.out.println("\nSee the elements of array\n");
                      System.out.print(a[c]+" ");
                            b[y]=a[c] ;
System.out.println("\nAfter deleting duplicate elements\n");
                     System.out.print(b[x]+" ");

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles