Click here to Skip to main content
16,007,610 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Opinions PinPopular
OriginalGriff27-Jul-10 20:38
mveOriginalGriff27-Jul-10 20:38 
GeneralRe: Opinions Pin
Rob Grainger27-Jul-10 23:00
Rob Grainger27-Jul-10 23:00 
GeneralRe: Opinions Pin
riced27-Jul-10 23:23
riced27-Jul-10 23:23 
GeneralRe: Opinions Pin
QuiJohn28-Jul-10 2:56
QuiJohn28-Jul-10 2:56 
GeneralRe: Opinions Pin
SirTimothy28-Jul-10 8:14
SirTimothy28-Jul-10 8:14 
GeneralRe: Opinions Pin
Gary R. Wheeler1-Aug-10 0:25
Gary R. Wheeler1-Aug-10 0:25 
GeneralRe: Opinions Pin
PIEBALDconsult28-Jul-10 3:18
mvePIEBALDconsult28-Jul-10 3:18 
GeneralRe: Opinions Pin
elchupathingy28-Jul-10 3:31
elchupathingy28-Jul-10 3:31 
GeneralRe: Opinions Pin
SirTimothy28-Jul-10 8:12
SirTimothy28-Jul-10 8:12 
GeneralRe: Opinions Pin
Luc Pattyn28-Jul-10 8:20
sitebuilderLuc Pattyn28-Jul-10 8:20 
GeneralRe: Opinions Pin
Jörgen Andersson28-Jul-10 5:10
professionalJörgen Andersson28-Jul-10 5:10 
GeneralRe: Opinions Pin
leonej_dt28-Jul-10 6:31
leonej_dt28-Jul-10 6:31 
GeneralRe: Opinions Pin
supercat928-Jul-10 6:59
supercat928-Jul-10 6:59 
GeneralRe: Opinions Pin
dybs28-Jul-10 16:29
dybs28-Jul-10 16:29 
GeneralRe: Opinions Pin
SirTimothy28-Jul-10 16:58
SirTimothy28-Jul-10 16:58 
JokeRe: Opinions Pin
johannesnestler2-Aug-10 3:00
johannesnestler2-Aug-10 3:00 
GeneralRe: Opinions Pin
SirTimothy3-Aug-10 15:54
SirTimothy3-Aug-10 15:54 
GeneralRe: Opinions Pin
Lutosław30-Jul-10 2:15
Lutosław30-Jul-10 2:15 
JokeRe: Opinions Pin
SirTimothy30-Jul-10 8:33
SirTimothy30-Jul-10 8:33 
GeneralRe: Opinions Pin
Lutosław31-Jul-10 2:07
Lutosław31-Jul-10 2:07 
SirTimothy wrote:
for((*prnt_func)(&ofs+ofs),y^=y,x&=~x;(y+1>=ARRAY_SIZE&&(x&&!(y=x&=~x)))||y+1<ARRAY_SIZE;(++y,iarray[y]<(y-1)
		[iarray])&&(y[iarray]^=iarray[y-1]^=iarray[y]^=*(iarray+y-1),x|=y));

I checked it and it gives correct results. I't amazing. Especially, I don't get why
y[iarray]

does not cause SEGFAULT or something. Where the O(n^2) complexity is hidden?

BTW. I had to implement all sorting algorithms as one of projets on my university. Bubble Sort was among them, but I did not care about performance so much.
void Bubble::Sort(Table &table, bool descending)
{
	bool swapped;
	int size = table.size();
	int bound = size - 1;
	int lastSwap = 0;
	do {
		swapped = false;
		for (int i = 0; i < bound; i++)
		{
			TableElement t1 = table[i], t2 = table[i + 1];
			if (descending ? t1 < t2 : t1 > t2) {
				swap(table[i], table[i+1]);
				swapped = true;
				lastSwap = i;
			}
		}
		bound = lastSwap;
	} while (swapped);
}

Greetings - Jacek

GeneralRe: Opinions Pin
SirTimothy31-Jul-10 4:50
SirTimothy31-Jul-10 4:50 
GeneralRe: Opinions Pin
Lutosław1-Aug-10 21:05
Lutosław1-Aug-10 21:05 
GeneralRe: Opinions Pin
Euhemerus8-Aug-10 1:45
Euhemerus8-Aug-10 1:45 
GeneralAre you sure that it's not null? Pin
JeremyBob22-Jul-10 21:39
JeremyBob22-Jul-10 21:39 
GeneralRe: Are you sure that it's not null? Pin
Yusuf23-Jul-10 13:37
Yusuf23-Jul-10 13:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.