Tag Info

New answers tagged

-4

Maybe going here a little of topic, but I think it's worth to mention, that AD 2015 you might consider using C++ instead of C. I don't want to got too deep into specifics, but your linked list is actually a great example, that once you start dealing with more complex data structures you end up creating your own quasi-C++ object oriented stuff and reinventing ...


3

For the numbers you gave, just brute force it. Here's a JavaScript program that brute forces it for 10 ingredients in the DB, 10 recipes in the DB, each recipe needs 2 ingredients, and I have 5 ingredients available: var i, j; var numIngredients = 10; var numRecipes = 10; var numIngredientsPerRecipe = 2; var numIngredientsInQuery = 5; function ...


2

Binary trees why use them? In programming you work a lot with collections of same type data. The two basic ways of storing this data are : linked lists and arrays. They both come with up and downsides: In a linked list it's easy to add elements at any position or remove elements. But access to a specific element is harder, because you have to go through ...


2

Any tree structure, where a node can have unlimited numbers of children, can be implemented using a binary tree. For each node in your tree, replace it with a node with a right and left pointer. The left pointer goes to the first of the node's children. The right node goes to the next sibling of the node. All the children of a given node are in a linked ...


0

One approach I like, to use your own term, is having "complex models" but asking the server how deeply you want the model to be filled. In your example, you might have an API call: GET /project?id=1337 That will return some basic representation of your model with attributes common across all use cases. Now you might be able to call the API with ...


23

No, binary trees are not for storing hierarchical data in the sense you're thinking of. The primary use case for n-ary trees, where n is a fixed number, is fast search capability, not a semantic hierarchy. Remember the old game where one person thinks of a number between 1 and 100, and the other has to guess it in as few guesses as possible, and if you ...


1

It's certainly do-able, but it's not small. An incomplete minimal example looks something like: template <typename BaseIterator, typename FieldType, FieldType SensorReading::*FieldPtr> class FilteredIterator { BaseIterator base_; typedef FilteredIterator<BaseIterator, FieldType, FieldPtr> self_type; public: // iterator type traits ...


9

In days of old, in data structures class we learned how AVL trees worked. I would have had that in one of my classes, but the instructor said "you'll never actually use this" and instead had us learn 2-3 trees and b* trees instead. Those were days when memory was tight and processes were signally threaded. You didn't use a deque when a singly linked list ...


0

Personally, I would rather use structures, but not one common, I would use one for each module instead, with the properties I need to "publish" for other modules to be able to use. Simple global variables are more difficult to maintain. Using a structure per module will get rid of unnecessary dependencies (data related to a single module, and only to that ...


0

Comment was getting too long, and my previous answer was complex enough not to further muddy it, but based on your VList link, here's another answer: Main data structure: List (no need to be linked) of arrays (I'll call them main_arrays), doubling in size whenever capacity is constrained. Start with 1 sized main_array, then add a 2-length main_array, then a ...


0

It took me a while to find something I thought to be authoritative and finally found this nugget from a Dr. Dobb's Journal 2001 article: "Intuitively, the standard-library vector class is like a built-in array: we can think of it as holding its elements in a single block of contiguous memory. Indeed, although the C++ Standard does not explicitly require ...


0

Finding very old STL documentation may not be as easy as it sounds. What I do recall from using STL back in 1996 was &vec[0] was already guaranteed to provide the beginning of the vector's array of data. I doubt there were any non-array implementations that met the original STL specs.


2

StackOverflow would be a somewhat better place for asking programming/algorithm related questions. In any case, the implementation you must have read would be based on "tables". Here is how such implementation works: Initialize vector with size n, say n = 16 Address: 0xAAA0 to 0xAAB0 Memory reserved Insert 17 elements. First 16 inserted fine. Next ...



Top 50 recent answers are included