Visit Our UNIX and Linux User Community


How to delete a duplicate element from below array.


 
Thread Tools Search this Thread
Top Forums Programming How to delete a duplicate element from below array.
# 1  
Old 04-05-2012
MySQL How to delete a duplicate element from below array.

Hello forum ,


Please solve the below queery.

A sorted array which has repated elements.

Code:
A[10] = {1,2,3,3,4,5,5,5,6,9,9}

i want to delete the duplicate elements and to genrate a new array.
i need the array sholud be like this
Code:
A[10] = {1,2,3,4,5,6,9}.

Please write the piece of code for above querry.



Thanks & Regards
Siva Ranganath.


Moderator's Comments:
Mod Comment This no script drive in - don't use a demanding language please, thanks.

Ordering people to do tasks for you in a demanding voice is not polite at all. Bear in mind that people here are volunteers and don't get payed by you.
Thanks for your understanding.

Last edited by zaxxon; 04-05-2012 at 10:22 AM.. Reason: Code tags, please! zaxxon: see [mod]
# 2  
Old 04-05-2012
What did you try so far?
# 3  
Old 04-05-2012
And what shell/language is this?
# 4  
Old 04-06-2012
I am sorry to say for detailed information.
please do it in C or C++.
# 5  
Old 04-06-2012
Code:
#include <iostream>
#include <algorithm>
 
const int SIZE = 21;
 
int main()
{
  int vals[SIZE] = {1,2,3,5,6,8,3,7,9,0,6,5,7,5,3,5,7,5,2,4};
 
  std::sort ( vals, vals + SIZE );
  int *end = std::unique ( vals, vals + SIZE );
   
  for ( int *it = vals; it != end; it++ )
    std::cout<< *it <<' ';
 
  std::cout<<std::endl;
}


Previous Thread | Next Thread
Test Your Knowledge in Computers #282
Difficulty: Easy
Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Array Element

This question is for someone that's more familiar with Array Element. I need to know if the maximum array element that can be assigned is 1024 and if its so, Is there a workaround solution when the counter exceeded 1024? param_array="$param_nam" counter=$counter+1 #to avoid space... (3 Replies)
Discussion started by: cumeh1624
3 Replies

2. Shell Programming and Scripting

Filter output as an array element

I am filtering the value of Server status from a file and am storing it in a temp file which I compare later to exit with appropriate status. I am wondering if I can directly output the value of Server status as an array element and then compare the value of elements to get the right exit status ... (2 Replies)
Discussion started by: paslas
2 Replies

3. Shell Programming and Scripting

ksh insert element in array

Hi all, I need help with the following scenario in ksh. If the number of elements contained by arrayA is 11 I need to insert a zero as the element arrayA then print all arrayA elements separated by comma. Appreciate your help. (9 Replies)
Discussion started by: ejianu
9 Replies

4. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

5. Programming

how to remove duplicate node data by searching tag element

hi everyone, I written one script that search all xml files and create one xml file, but I need to remove some duplicate nodes by testing one tag element. </Datainfo> <data> <test>22</test> <info>sensor value</info> <sensor> <sensor value="23"... (0 Replies)
Discussion started by: veerubiji
0 Replies

6. Shell Programming and Scripting

remove an element from array

I need to remove an element from the below array variable TABLENAME. #!/bin/ksh set -A TABLENAME "mirf roxar keke mirs" echo "the array is ${TABLENAME}" If i need to remove say keke and have the final TABLENAME as below, how this could be achieved. Pls throw some light. echo "Modified... (3 Replies)
Discussion started by: michaelrozar17
3 Replies

7. Shell Programming and Scripting

Help! Yet another check element in array Question

Greetings, DISCLAIMER: My shell scripting is rusty so my question may be borderline stupid. You've been warned. I need to create a script that a) lists the content of zip files in a directory and b) sends out an `exception` report. My ZIP files contain a control file (for load check). I want... (2 Replies)
Discussion started by: alan
2 Replies

8. Shell Programming and Scripting

Shift array element

I want to delete and 0th element of array in shell scrpit and also shift all others to one level up. (2 Replies)
Discussion started by: darshakraut
2 Replies

9. Shell Programming and Scripting

Perl delete an element from array

Probably I am not seeing it or I am not using the "delete" correctly I had the following codes but it does not work for me #!/bin/perl -w ... @sysFile1 = (a_b, a_c, a_d); @sysFile2 = (a_c, a_e, b_f); foreach $line1 (@sysFile1){ trim(\$line1); (my $tmp1, my $tmp2) = split/_/,... (6 Replies)
Discussion started by: ahtat99
6 Replies

10. Shell Programming and Scripting

accessing my first element of array

Hello everyonel, I have an array set like so num=4 read name arr=name I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr} it will show the last element... (4 Replies)
Discussion started by: afadaghi
4 Replies

Featured Tech Videos