answersLogoWhite

0


Best Answer

A stack is implicitly sorted by hierarchical nested order. It does not make sense to sort a stack.

Do you mean a list? If so, please ask the question again.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to sort an unsorted stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a standard basic program?

That really depends on what sort of program you are trying to build, what do you want the program to do?


In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


Write a program in c to sort the details of 10 students using the structure?

for(i = 0; i < num_students; i ++){ sort(student[i]); } That's what you get when you're that specific!


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Do glaciers sort the material they transport?

No. Material that is directly deposited by glaciers, called till, is completely unsorted. However, some of the processes around glaciers, particularly streams from meltwater, can sort material.


How do you write an algorithm for list of names in ascending order?

If they're in an array, use java.util.Arrays.sort(). If they're in a Collection, as in java.util.Collection, use java.util.Collections.sort(). If you want an actual algorithm, try a for-each loop with an equivalence operator and conditional switch.


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Is there any way to perform quick sort other than stack?

Stack is not a way to perform quicksort, it is a tool used to implement recursion.


Where do you write a story on your computer?

Most computers nowadays come with some sort of word processing program like Microsoft Word - just open that program and follow the directions to get started!


Can you implement merge sort without using recursion?

Sure, recursion can always be substituted with using a stack.


How can you make a turbo c program by using one for loop to sort 3 numbers in ascending order?

Use the insertion sort algorithm. Insertion sort works on the premise that a set of 1 can always be regarded as a sorted set, thus in a set of n elements, we can divide the set in two, with a sorted set at the beginning (with 1 element) and an unsorted set at the end (with all other elements). We then take the first element of the unsorted set and insert it into the sorted set, repeating until the unsorted set is empty. We take the first element out of the unsorted set by copying it to a temporary variable, thus creating a gap in its place. We then examine the element to the left of the gap and, if the value is greater than the temporary, we copy it into the gap, effectively moving the gap one place to the left. We stop moving the gap when we reach the start of the array or the element to the left of the gap is not greater than the temporary. We then copy the temporary into the gap, increasing the sorted set by one element and reducing the unsorted set by one element. We can implement this algorithm using just one for loop: void sort (int* a, unsigned s) { // assume a refers to an array of length s for (int i=2; i<s; ++i) { int t = a[i]; // temporarily store a[i] outside the array int g = i; // index g is the "gap" in the array while (0<g && t<a[g-1]) { a[g]=a[g-1]; --g; } // move the gap to the correct insertion point a[g] = t; // insert the temporary } } Thus, to sort 3 numbers: int a[3] = {2, 3, 1}; // unsorted sort (a, 3); assert (a[0]==1); assert (a[1]==2); assert (a[2]==3);


What are the applications of selection sort?

None. Selection sort can only be used on small sets of unsorted data and although it generally performs better than bubble sort, it is unstable and is less efficient than insert sort. This is primarily because insert sort only needs to scan as far back as required to perform an insertion whereas selection sort must scan the entire set to find the lowest value in the set. And although selection sort generally performs fewer writes than insert sort, it cannot perform fewer writes than cycle sort, which is important in applications where write speed greatly exceeds read speed.