Question: Write a C program to take a sequence of n integer values and remove duplicate occurrences, i.e. only the first occurrence of each value will

Write a C program to take a sequence of n integer values and remove duplicate occurrences, i.e. only the first occurrence of each value will remain. n will be the first input value and the sequence may be read using scanf()s. The phases for performing this task are:

a. Read input sequence of values, each value giving an ordered pair (value, position indicator).

b. Sort the pairs in ascending order by value in a stable fashion. If your chosen sort is stable, then the key is just the value. If your chosen sort is unstable, the key must be extended with the position indicator.

c. Using one pass (big theta (n) time) over the sorted result, remove any occurrences beyond the first one for a key.

d. Sort the pairs using the (unique) position indicator as the key.

e. Output the number of unique values followed by the values (without the position indicators).

The input will be read from standard input (stdin) as either keyboard typing or as a shell redirect (<) from a file. Prompts/menus are completely unnecessary!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!