A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.
1
vote
2answers
5k views
Deleting a node from Binary Search Tree
I have read about it at few places and tried to write my own version, would like to get it reviewed.
class Node {
private int value;
private Node left;
private Node right
// ...
1
vote
1answer
57 views
Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the ...
1
vote
3answers
2k views
Stack class C++
Please code review
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
template <class T>
class Stack
{
public:
Stack() {}
void push(T x);
...
0
votes
1answer
73 views
Dictionary Structure
I am brand new to dictionaries and coding and am hoping to get some suggestions on how I should structure my dictionary.
I have a collector number which has meters connected to them. Each of the ...
5
votes
1answer
605 views
Implementations of prefix lookup tables in Python
I've got a fairly performance sensitive need for fast prefix lookup, and I've built two different implementations trying to optimize for my use case. The first is built off a Trie implementation, and ...
1
vote
2answers
55 views
Check if a Binary Tree <String> is aBinary Search Tree
i'm understanding the question but wanna make sure if my implementation is correct or not =|
The Q is :
Write a method that accepts as its argument a BinaryTree object and returns true if the ...
1
vote
1answer
69 views
Singly Linked List (strings only)
This is my attempt at constructing a singly-linked-list with basic functions. I initially tried to build the whole list as a series of nodes, but ran into problems when trying to remove or pop ...
0
votes
2answers
72 views
remove all nodes with same value in a linked list
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return ...
4
votes
2answers
6k views
Doubly Linked List C++
Please, review the code:
#include <iostream>
using namespace std;
template <class T>
struct Node
{
Node(T data) : data(data), next(NULL), prev(NULL) {}
T data;
Node * next;
Node ...
5
votes
4answers
143 views
Readability and Performance of my Trie implementation
As an interesting exercise in Python 3.3, I implemented a Trie (also known as a Prefix Tree).
Example usages
Create from list of key-value-tuples
mapping = (('she', 1), ('sells', 5), ('sea', 10), ...
-1
votes
2answers
72 views
What is a good name for bidirectional dictionary structure? [closed]
I'm writing a generic bidirectional dictionary which will be a part of a (somewhat) public API. This is how the dictionary works:
It will hold key-key pairs where key1 and key2 will be two different ...
1
vote
0answers
25 views
Is this code for getting the dependency tree of a file correct?
function dep_tree(graph,node,prev_deps){
return uniq(flatten(graph[node].map(function(child_node){
if (contains(prev_deps,child_node))
throw "Circular reference between ...
1
vote
1answer
38 views
Refactor making a tree with hash input?
I initialized a tree using a nested hash as input, but when I recursively call Tree.new on the children, it doesn't seem to pass each child as a hash. As a pretty ugly, but working, alternative, I ...
1
vote
2answers
36 views
Mapping enum to enum - is this an efficient and elegant implementation
I need to map from one enum type to another. Here is the enum I am
given:
enum CfgFruitType { CFGNoFruit, CFGApple, CFGApricot, CFGBanana,
CFGMango, CFGKiwi, CFGFig, CFGGrape, CFGMelon, CFGLemon,
...
1
vote
1answer
49 views
Double linked list with different dependencies
I need to connect different Task with a double linked list and different Dependencies which affect a calculation for which I need the values of both Task:
public class Task {
private ...