Logo

Programming-Idioms

History of Idiom 8 > diff from v35 to v36

Edit summary for version 36 by programming-idioms.org:
Restored version 33

Version 35

2016-11-29, 03:15:55

Version 36

2016-11-29, 20:06:34

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
#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);	
	
}
Code
std::map<const char*, int> x;
x["one"] = 1;
x["two"] = 2;
Doc URL
http://www.cplusplus.com/reference/map/map/
Doc URL
http://www.cplusplus.com/reference/map/map/
Code
s
Code
x = {"one": 1, "two":2}
Demo URL
http://ideone.com/PeXCe1
Demo URL
http://ideone.com/PeXCe1