Write, efficient code for extracting unique elements from
a sorted list of array.

e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

Answer Posted / abraham

/* Using the same array and no extra storage space*/
/* "Nothing's far when one wants to get there." */

#include<stdio.h>

main()
{
int a[] = {1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9,10};
int cur = 0;
int i = 0;

for (i = 1 ; i < (sizeof(a)/4) ;i++)
{
if ( a[cur] != a[i])
{
++cur;
if (cur != i)
{
a[cur] = a[i];
}
}
}
a[++cur] = '\0';
for (i =0 ; i< cur;i++)
printf ("%d\n",a[i]);
}

Is This Answer Correct ?    2 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program for area of circumference of shapes

2023


Cluster head selection in Wireless Sensor Network using C programming language.

3094


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2248


write a simple calculator c program to perform addition, subtraction, mul and div.

3130


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3698






What is data _null_? ,Explain with code when u need to use it in data step programming ?

2809


How can you relate the function with the structure? Explain with an appropriate example.

2909


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2314


write a function to give demostrate the functionality of 3d in 1d. function prototye: change(int value,int indexX,int indexY,int indexZ, int [] 1dArray); value=what is the date; indexX=x-asix indexY=y-axis indexZ=z-axis and 1dArray=in which and where the value is stored??

4128


What is full form of PEPSI

1852


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2215


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2851


Write a program to model an exploding firecracker in the xy plane using a particle system

3679


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2008


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

2396