473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

JAVA

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
4 1161
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.