Quick Search for:  in language:    
good,method,removing,duplicates,arrayCOMMENTS
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 681,728. lines
 Jobs: 96. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for C/ C++.
Yet another Console Space Invaders
By Steven McElrea on 11/28


PrimeTester
By Titus Laska on 11/28


Click here to see a screenshot of this code!Commander
By Hylke Donker on 11/27

(Screen Shot)

Game Trees and minimax method (minima maxima)
By Hasan Alayli on 11/27


Origin of Computer Games!
By suneet singh on 11/27


CD Tray Open
By pr0ger on 11/27


Click here to see a screenshot of this code!Maze solver using backtacking & recursion
By Hasan Alayli on 11/27

(Screen Shot)

Grand TicAttackToy
By Divine Light on 11/27


Word Deriver thru stack operations
By Sayash Kumar on 11/26


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

REMOVE DUPLICATES IN ARRAY

Print
Email
 
VB icon
Submitted on: 11/21/2003 10:40:36 AM
By: Renjini S 
Level: Beginner
User Rating: Unrated
Compatibility:C

Users have accessed this code 300 times.
 
 
     A good method for removing duplicates in an array COMMENTS INCLUDED
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

//**************************************
//     
//INCLUDE files for :REMOVE DUPLICATES I
//     N ARRAY
//**************************************
//     
#include <stdio.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: REMOVE DUPLICATES IN ARRAY
// Description:A good method for removin
//     g duplicates in an array
COMMENTS INCLUDED
// By: Renjini S
//
// Inputs:Array elements
//
// Returns:array with duplicates removed
//     
//
// Assumes:Array should be in sorted ord
//     er
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=7144&lngWId;=3//for details.//**************************************
//     

/*
A PROGRAM for REMOVING DUPLICATES FROM AN ARRAY AND THEREBY CONTRACTING THE ARRAY.
CONSECUTIVE ELEMENTS ARE COMPARED for EQUALITY.
INPUTS: ARRAY ELEMENTS
OUPUT: ARRAY WITH DUPLICATES REMOVED
ASSUMPTIONS: ARRAY SHOULD BE IN SORTED ORDER (ASCENDING)
SIDE EFFECTS: MAY NOT BE EFFICIENT for LARGE ARRAYS
VARIABLES USED:
	i : for array traversal
	j : for keeping track of distinct numbers
*/
#include <stdio.h>
#define ARRAYSIZE 10
void main()
    {
    int arr[ARRAYSIZE],i,j;
    printf("Enter the array elements\n");
    for(i=0;i<ARRAYSIZE;i++)
    scanf("%d",&arr;[i]);
    printf("Removing duplicates.....\n");
    i=1;//the position of arr[0] does not change
    while(arr[i-1]!=arr[i] && i<ARRAYSIZE)	//it is necessary to start shifting elements 
    i=i+1;					//only after the first duplicate is encountered. this is efficient
    						//when the array has no duplicates.
    if(i==ARRAYSIZE)//no duplicates
    j=i;
    else
        {
        j=i-1;
        while(i<ARRAYSIZE)
            {
            i=i+1;
            if(arr[i-1]!=arr[i])
                {
                j=j+1;
                arr[j]=arr[i];	//if there are j distinct elements, they should occupy postions from 0 to j-1			
            }

}
}
printf("Array after removing duplicates......."); for(i=0;i<j;i++) printf(" %d",arr[i]); printf("\n"); }


Other 2 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
11/23/2003 9:00:49 AM:stephen antony
good why cant you visit my 
site
www.codepark.tk
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.