Logo

Programming-Idioms

History of Idiom 8 > diff from v33 to v34

Edit summary for version 34 by lavi:
[Cpp]

Version 33

2016-11-28, 22:30:24

Version 34

2016-11-29, 03:15:06

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
#include <map>
Imports
#include <map>
Code
std::map<const char*, int> x;
x["one"] = 1;
x["two"] = 2;
Code
#include "BinaryTree.h"
#include <iostream>
using std::cout;
using std::endl;

BinaryTree::BinaryTree()
{
	rootNode = NULL;
}

BinaryTree::~BinaryTree()
{
	if(rootNode == NULL)
		return;		// Nothing to do
	removeSubtree(rootNode);
}

void BinaryTree::removeSubtree(BinaryTreeNode* x)
{
	if(x == NULL)
		return;	// Nothing to do
		
	BinaryTreeNode* left = x->leftNode;
	BinaryTreeNode* right = x->rightNode;
	
	delete x;
	removeSubtree(left);
	removeSubtree(right);	
	
}
Doc URL
http://www.cplusplus.com/reference/map/map/
Doc URL
http://www.cplusplus.com/reference/map/map/