By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

JAVA

P: n/a
i want to ascending sort a word through bubble sort. Suppose i give
kolkata and the output will be like aakllot. i.e. the result. plz give
me full program code. i am beginner. plz help me.

Dec 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ka***********@gmail.com said:
i want to ascending sort a word through bubble sort. Suppose i give
kolkata and the output will be like aakllot. i.e. the result. plz give
me full program code. i am beginner. plz help me.


I suggest you get yourself a copy of "The C Programming Language", 2nd
edition, by Brian W Kernighan and Dennis M Ritchie, and work your way
through the text and the exercises, slowly and carefully. At some point,
you will either give up on the language completely or acquire a skill level
which renders the above question so trivial that you will be embarrassed at
ever having asked people to solve it on your behalf.

In the meantime, please remember that the Subject line is supposed to
describe the subject of the article, not your favourite flavour of coffee.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 15 '05 #2

P: n/a
i want to ascending sort a word through bubble sort. Suppose i give
kolkata and the output will be like aakllot. i.e. the result. plz give
me full program code. i am beginner. plz help me.


This one is easy for beginners, using only for loops :

#include <stdio.h>

int main(void)
{
char
For []="kolkata";char *
fOr =
For ,*_,
foR ;
for (;*
fOr ;
fOr ++)
for (_=
fOr ;*_;(*
fOr <*_)||(
foR =*_,*_=*
fOr ,*
fOr =
foR ),_++);return puts(
For );
}

Dec 15 '05 #3

P: n/a
Gerr said:
i want to ascending sort a word through bubble sort. Suppose i give
kolkata and the output will be like aakllot. i.e. the result. plz give
me full program code. i am beginner. plz help me.


This one is easy for beginners, using only for loops :


Delightful!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 15 '05 #4

P: n/a
ka***********@gmail.com wrote:

i want to ascending sort a word through bubble sort. Suppose i give
kolkata and the output will be like aakllot. i.e. the result. plz give
me full program code. i am beginner. plz help me.


/* BEGIN new.c */

#include <stdio.h>
#include <string.h>

void b_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

int comparison(const void *a, const void *b);

int main(void)
{
char s[] = "kolkata";

puts(s);
b_sort(s, sizeof s - 1, sizeof *s, comparison);
puts(s);
return 0;
}

int comparison(const void *a, const void *b)
{
const char *const letters = "abcdefghijklmnopqrstuvwxyz";
int aa = *(char *)a;
int bb = *(char *)b;

return (int)(strchr(letters, aa) - strchr(letters, bb));
}

void b_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
unsigned char *last, *next, *middle;
unsigned char *p1, *p2, *end, swap;

if (nmemb-- > 1) {
last = base;
last += nmemb * size;
do {
middle = next = base;
do {
if (compar(middle, middle + size) > 0) {
p1 = middle;
p2 = middle + size;
end = p2 + size;
do {
swap = *p1;
*p1++ = *p2;
*p2++ = swap;
} while (p2 != end);
next = middle;
}
middle += size;
} while (middle != last);
last = next;
} while (last != base);
}
}

/* END new.c */
--
pete
Dec 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.