Question

Write a C function to process arrays (1D and 2D), select sort, quick sort

Write a C function to process arrays (1D and 2D), select sort, quick sort

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For select sort :

Void sel_sort( int arr[],int n )

{ Int i,min,j;

For(i=0;i<n-1;i++)

Min = i;

For(j=i+1;j<n;j++)

{

If(arr[j]<arr[min])

Min=j;

}

Swap(arr,min,i);

}

Swap (int arr[],int i,int j)

{

Int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

For quick sort :

Quick_sort(int arr[],int l, int h)

{

Int p=partision(arr,l,h);

Quick_sort(arr,l,p-1);

Quick_sort(arr,p+1,h)

}

}

Partision(int arr[],int l,int h)

{ Int x,i,j;

x =arr[h];

i = ( l -1) ;

For(j=l;j<h-1;j++)

{ If (arr[j]<x)

{

i++;

Swap(&arr[i],arr[j]]);

}

}

Swap(&arr[i+1],&arr[h]);

Return i+1;

}

Swap (int *a,int *b)

{

Int temp=*a;

*a=*b;

*b=temp;

}

For string :

Void reverse()

{

If (c !='\n')

{

Reverse ();

Printf("%c",c);

}

}

Add a comment
Know the answer?
Add Answer to:
Write a C function to process arrays (1D and 2D), select sort, quick sort
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments...

    Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments int a[ROW][COL], int b[ROW][COL], m, n (m and n are the size of the rows and columns correspondingly). It returns true if all the corresponding elements are equal in a and b, otherwise false. Write the main function. Initialize two arrays (e.g. 3*4 dimension).

  • C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick...

    C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays of size 5000, 50000, and 500000. For...

  • C programming Strictly - Write a program to sort an array of integers via arrays of...

    C programming Strictly - Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...

  • Please write a tic tac toe game using c++ language and 1D arrays, thank you!

    Please write a tic tac toe game using c++ language and 1D arrays, thank you!

  • Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays....

    Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...

  • Write a C# program(s) using arrays Create a 2D array of integers [8,4] Create a 3D...

    Write a C# program(s) using arrays Create a 2D array of integers [8,4] Create a 3D array of integers [4,4,2]

  • Write a Python function to implement the quick sort algorithm over a singly linked list. The...

    Write a Python function to implement the quick sort algorithm over a singly linked list. The input of your function should be a reference pointing to the first node of a linked list, and the output of your function should also be a reference to the first node of a linked list, in which the data have been sorted into the ascending order. (You may use the LinkedQueue class we introduced in the lecture directly in your program.)

  • Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D...

    Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...

  • Order Statistics: A. Given two sorted arrays X and Y of equal size n, use Quick-Select...

    Order Statistics: A. Given two sorted arrays X and Y of equal size n, use Quick-Select to find the median of all 2n elements in arrays X and Y. Can you improve Quick-Select by choosing better pivots at every step?(in java) B. Show some experiments of your improved Quick-Select with arrays of size n=50. You can assume, if you want, that all the elements in the two arrays are distinct.

  • Data Structure using C++ only Write 4 different sorting functions: Selection Sort, Insertion Sort, Merge Sort...

    Data Structure using C++ only Write 4 different sorting functions: Selection Sort, Insertion Sort, Merge Sort and Quick sort. For each sort you may store the numbers in an array or a linked list (this may be different for each sort). Write your program so that it accepts arguments from the command line using argc and argv in the main function call.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT