Question

In: Computer Science

Use C language. I have random array [4,2,7,1,9,8,0]. Sort the array's index but cannot change the...

Use C language.

I have random array [4,2,7,1,9,8,0].

Sort the array's index but cannot change the position of item in the array, if you copy the array to a new array, you also cannot change the item's position in array.

The index now is[0,1,2,3,4,5,6]

The output should be[6,3,1,0,2,5,4]

Solutions

Expert Solution

Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,a[10],helper(int [],int);
clrscr();
printf("enter the number of elements:");
scanf("%d",&n);
printf("enter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
helper(a,n);
getch();
}


int helper(int a[],int n)
{
int b[10],c[10],i,j,temp,ele;
for(i=0;i<n;i++)
{
b[i]=a[i];
}
for(i=n-1;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
ele=b[i];
if(ele==a[j])
{
c[i]=j;
}
}
}
printf("Indexes are:");
for(i=0;i<n;i++)
{
b[i]=a[i];
printf("%d,",c[i]);
}
}


Reference:

Output:


Related Solutions

(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
i have an array of strings, how do i sort them into a binary tree? C...
i have an array of strings, how do i sort them into a binary tree? C Program
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using malloc or calloc. Examples: Input: n = 5, A= {33,21,2,55,4} Output: {2,4,21,33,55} b) Write a function that declares an array of 256 doubles and initializes each element in the array to have a value equal to half of the index of that element. That is, the value at index 0 should be 0.0, the value at index 1 should be 0.5, the value at...
Write a Y86 program in C language that sorts an array of data using Bubble Sort....
Write a Y86 program in C language that sorts an array of data using Bubble Sort. Allow the user to input up to 10 numbers from the keyboard. Sort the array in place (i.e., no need to allocate additional memory for the sorted array). Your program should be a complete one
language is c++ I need to take a num and put it into an array one...
language is c++ I need to take a num and put it into an array one number at a time suck that the hundredths place is at 10^3, tens is 10^2 and so on For milestone 1 you need to build a constructor that converts a int to a bigInt You need to peel off each digit from the int and place it into the appropriate location in the array of int. To do this you need to use integer...
(C++)Counting Sort: Write C++ codes for counting sort. The input array is A = {20, 18,...
(C++)Counting Sort: Write C++ codes for counting sort. The input array is A = {20, 18, 5, 7, 16, 10, 9, 3, 12, 14, 0}
How would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array.
JAVA ProgrammingHow would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array. index 4 is the 5th smallest element in the array, index 9 is the 10th smallest element in the array and so on...- this array could be small (like 5 indexes) or large (like 100,000 indexes).- all other numbers do not change position
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Explain this code: The structure used is max heap using array. C++ (i is the index...
Explain this code: The structure used is max heap using array. C++ (i is the index of the element to be deleted) void del(int i) {    int left,right,temp;    arr[i]=arr[n-1];    n=n-1;    left=2*i+1; /*left child of i*/    right=2*i+2; /* right child of i*/    while(right < n)    {        if( arr[i]>=arr[left] && arr[i]>=arr[right] )            return;        if( arr[right]<=arr[left] )        {            temp=arr[i];            arr[i]=arr[left];   ...
develop a  multithreaded version of radix sort c language
develop a  multithreaded version of radix sort c language
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT