I need help with re-ordering the values in ascending order in the array (Unordered). However, I cannot use swap or sort function (i.e. Bubblesort).

How can I do that?

Recommended Answers

All 7 Replies

Is there a seperate function provided by C to sort and swap?

Sort values in an array without using sort functions (Urgent)

What does this mean anyway?
Are you asking to make a custom sorting function?

yes, I have to make my own sorting function .. but I have no idea how can i make it, all I have in my mind is very close to buble sort ...

I don't see how this is urgent in any way whatsoever.
Putting that in your thread title wont make anyone more inclined to help you.

As for your actual question, I guess you could make a new array, and insert them in ordered one number at a time.

the various search algorithms are described on wikipedia (search for "sort algorithms") and elsewhere on t'internet. have a look on there and you should be able to implement one in C

I know there are many sorting algorithm! But i, restricted to use any of them, i should make my own one .. the way William Hemsworth told is close to insertion sort .. ah i can't figure out how can i make it :((((

>restricted to use any of them, i should make my own one
That's stupid. You're not likely to invent a sorting algorithm that hasn't been invented before, and yours is much more likely to suck ass than one of the existing popular ones. I think you need to confirm what your assignment restrictions really mean.

My guess is that you can't use a pre-written sort function, but you can write your own function that implements insertion sort, selection sort, etc... The restriction being there to force you to write and understand the code rather than reuse something that somebody else wrote.

Listen fedya, if what Narue said is correct (that you have to INVENT a new algorithm for sorting) you have to keep two things in mind

  • It should be faster that quick sort
  • It should be highly efficient for a particular type of data arrangement

Scientists are spending sleepless nights trying to find newer methods of sorting. If you are a scientist (which I doubt, no offense bub), you should get in touch with some of your MIT buddies and have a good chat with them. Only a few selected individuals can help you here

If you are NOT trying to invent an algorithm, then try to rephrase the question because I seriously can't understand what you are trying to say.

By the way, I just remembered I made a sorting algorithm but I can't say whether it's any good or not. Just check whether it's different from BUBBLE and SELECTION

PS - Please don't give -ve rep for "giving away the answer", I'm just showing what I've produced.


int main()
	int a[10];	int i;
	int j;    	int tmp;
	int m;

	printf("\n\n\tEnter The Numbers\n");
	for(i = 0;i < 10;i++)
		scanf("%d", &a[i]);

	printf("\n\n\tThis Is Your Original Array : \n\n");
	for(i = 0;i < 10;i++)
		printf("%d\t", a[i]);


	for(i = 0;i < 9;i++)
		for (j = i + 1;j < 10;j++)
			if (a[i] > a[j])
				tmp  = a[i];
				a[i] = a[j];
				a[j] = tmp;

				for(m = 0;m < 10;m++)
					printf("%d\t", a[m]);

	printf("\n\n\tThis Is Your Sorted Array : \n\n");
	for(i = 0;i < 10;i++)

	return 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.