Click here to Skip to main content
15,897,891 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 8:29
mvahoney the codewitch13-Sep-19 8:29 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
Nand3213-Sep-19 23:41
Nand3213-Sep-19 23:41 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
User 483504713-Sep-19 6:03
User 483504713-Sep-19 6:03 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 7:03
mvahoney the codewitch13-Sep-19 7:03 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
User 483504713-Sep-19 7:09
User 483504713-Sep-19 7:09 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 7:11
mvahoney the codewitch13-Sep-19 7:11 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
User 483504713-Sep-19 7:25
User 483504713-Sep-19 7:25 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 7:49
mvahoney the codewitch13-Sep-19 7:49 
This is a splay tree. Worst case is different because it's doing tree rotations.

Yes, I could increase the stack size but that's not really the proper way to do this - that's like cleaning your carpet with a blowtorch - i mean sure, it gets rid of the filth, but...

but i am tempted. THis is the function i need to make non-recursive:

C#
_Node _Splay(_Node root, TKey key)
{
	// TODO: if this function wasn't recursive it could deal with more items
	int c;
	// Base cases: root is null or key is present at root 
	if (null==root || 0==(c = _comparer.Compare(root.Key, key)))
		return root;

	// Key lies in left subtree 
	if (0<c)
	{
		// Key is not in tree, we are done 
		if (null==root.Left)
			return root;
		c = _comparer.Compare(root.Left.Key, key);
		// Zig-Zig (Left Left) 
		if (0<c)
		{
			// First recursively bring the key as root of left-left 
			root.Left.Left = _Splay(root.Left.Left, key);

			// Do first rotation for root, second rotation is  
			// done after else 
			root = _Ror(root);
		}
		else if (0>c) // Zig-Zag (Left Right) 
		{
			// First recursively bring the key as root of left-right 
			root.Left.Right = _Splay(root.Left.Right, key);

			// Do first rotation for root.left 
			if (null!=root.Left.Right)
				root.Left = _Rol(root.Left);
		}

		// Do second rotation for root 
		return (null==root.Left) ? root : _Ror(root);
	}
	else // Key lies in right subtree 
	{
		// Key is not in tree, we are done 
		if (null==root.Right)
			return root;
		c = _comparer.Compare(root.Right.Key, key);
		// Zag-Zig (Right Left) 
		if (0<c)
		{
			// Bring the key as root of right-left 
			root.Right.Left = _Splay(root.Right.Left, key);

			// Do first rotation for root.right 
			if (null!=root.Right.Left)
				root.Right = _Ror(root.Right);
		}
		else if (0>c)// Zag-Zag (Right Right) 
		{
			// Bring the key as root of right-right and do  
			// first rotation 
			root.Right.Right = _Splay(root.Right.Right, key);
			root = _Rol(root);
		}

		// Do second rotation for root 
		return (null==root.Right ) ? root : _Rol(root);
	}
}


=( =( =(
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

GeneralRe: yay i published my b-tree and binary tree classes finally Pin
User 483504713-Sep-19 8:08
User 483504713-Sep-19 8:08 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 8:16
mvahoney the codewitch13-Sep-19 8:16 
GeneralRe: yay i published my b-tree and binary tree classes finally Pin
honey the codewitch13-Sep-19 8:44
mvahoney the codewitch13-Sep-19 8:44 
GeneralMessage Removed Pin
13-Sep-19 1:24
Ganeshre13-Sep-19 1:24 
GeneralWSO CCC OTD (themed) 2019-09-13 PinPopular
OriginalGriff12-Sep-19 21:51
mveOriginalGriff12-Sep-19 21:51 
GeneralRe: WSO CCC OTD (themed) 2019-09-13 Pin
PeejayAdams12-Sep-19 22:07
PeejayAdams12-Sep-19 22:07 
GeneralRe: WSO CCC OTD (themed) 2019-09-13 - we have a winner! Pin
OriginalGriff12-Sep-19 22:15
mveOriginalGriff12-Sep-19 22:15 
GeneralNot the WSO CCC OTD 2019-09-13 Pin
OriginalGriff12-Sep-19 21:16
mveOriginalGriff12-Sep-19 21:16 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
Abbas A. Ali12-Sep-19 21:35
professionalAbbas A. Ali12-Sep-19 21:35 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
OriginalGriff12-Sep-19 21:42
mveOriginalGriff12-Sep-19 21:42 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
Abbas A. Ali12-Sep-19 21:47
professionalAbbas A. Ali12-Sep-19 21:47 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
OriginalGriff12-Sep-19 21:50
mveOriginalGriff12-Sep-19 21:50 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
PeejayAdams12-Sep-19 22:03
PeejayAdams12-Sep-19 22:03 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
OriginalGriff12-Sep-19 22:06
mveOriginalGriff12-Sep-19 22:06 
GeneralRe: Not the WSO CCC OTD 2019-09-13 Pin
DRHuff13-Sep-19 3:32
DRHuff13-Sep-19 3:32 
GeneralSound of the Week Pin
Sander Rossel12-Sep-19 21:09
professionalSander Rossel12-Sep-19 21:09 
GeneralRe: Sound of the Week Pin
peterkmx13-Sep-19 3:43
professionalpeterkmx13-Sep-19 3:43 

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.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   357 votes