data-structures

What is the point of PHP's SplDoublyLinkedList class, and more importantly, Linked Lists in general?

On a quest to expand my programming prowess, I've delved ever-so-slightly into The Standard PHP Library. This led to my discovery of the SplDoublyLinkedList class. From there I read the descriptions of Linked Lists and Doubly Linked Lists on Wikipedia. I understand how they work... But I cannot conceive of a reason WHY we need itor b...

When designing a data structure, should helper methods be accessible to other users?

I had a talk with my professor today about the layout of the Chunklist data structure that we've been working on. Basically, it is a hybrid of a ordered circular linked list with each node containing an arraylist. Since this is an ordered list, the add() method is pretty complicated, so I wrote a nested class to hold the helper methods...

How would I implement a QueueDictionary, a combination of Queue and Dictionary in C#?

Basically the data structure I want would mirror a MSMQ but would be in memory, because it is being used in the one process. By mirroring MSMQ I mean you would enqueue objects, then you could either dequeue objects or retrieve them using a key. Here is me initial attempt. My main problem with this attempt is that the Get by id would be u...

static allocated data structures

I'm working on a existing embedded system (memory is limited, Flash is limited, ...) with an RT OS. All data structures have a fixed size and are allocated at "compile time" and are therefore suited for RT. There is no dynamic memory allocation. The programming language is C++, but there is no STL available. I like to replace some of the...

store data dynamically coming from database - c++

hi, Can you give me a idea about the best way that can i store the data coming from the database dynamically. I know the number of columns before, so i want to create a data structure dynamically that will hold all the data, and i need to reorganize the data to show output. In one word - when we type the query "select * from table" - re...

What should I use Clojure's finger trees for?

Clojure's new contrib library group has a finger tree library. What are the use cases for finger trees in clojure? When should finger trees be used instead of one of clojure's other peristent data strucures: vectors, sets, maps, persistentqueues, etc. The Joy of Clojure mentions that Finger trees can be used for indexed collections wh...

Data structure with two primary keys? (caching lat/lon address pairs)

I'm trying to cache lat/lon address pairs from Google Maps, so I need a data structure where the key is two ints (lat and lon). What's the simplest data structure for that? I thought of two ways so far: Nested hash: {37.734608 {-121.913019 "San Ramon, CA" -121.6 "Tracy, CA"}} Concat the two to make the key: {"37.734608,-121.913019"...

Why the space complexity of this algorithm is O(1)

Hi all: i read the algorithm below to find the lowest common ancestor of two nodes in a binary search tree. /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; struct node* newNode(int ); /* Function to find least co...

Is Object the preferred Associative Container in AS3?

I've been using Object as a way to have a generic associative array (map/dictionary) since AS3/Flex seems to be very limited in this regard. But I really don't like it coming from a C++/Java/C# background. Is there a better way, some standard class I've not come across... is this even considered good/bad in AS3? ...

Hash table: why size should be prime?

Why is it necessary for a hash table's (the data structure) size to be a prime? From what I understand, it assures a more even distribution but is there any other reason? ...

Cyclic and acyclic data structures

What is the difference, can you give me examples, thanks in advance ...

C++ remove node binary search tree

...

Fix depth tree in Python

I want to implement a tree structure which has fixed depth, i.e. when adding children to the leef nodes, the whole tree structure should "move up". This also means that several roots can exist simultaneously. See example beneath: In this example, the green nodes are added in iteration 1, deleting the top node (grey) and making the two b...

Mapping from String to integer - performance of various approaches

Let's say that I need to make a mapping from String to an integer. The integers are unique and form a continuous range starting from 0. That is: Hello -> 0 World -> 1 Foo -> 2 Bar -> 3 Spam -> 4 Eggs -> 5 etc. There are at least two straightforward ways to do it. With a hashmap: HashMap<String, Integer> map = ... int integer = ...

Linked Lists, Assigning char array [C]

Hi all. I've got the task of making a car rental program, which uses linked lists to control what cars are available for rent, are rented, or are in repair. The 'car' is a structure, and so is the rented list, available list, and repair list. Heres my current issue. If the user wants to make a new car available, we must add it to our l...

Java - How to separate a list based on a property of it's elements

Hi, I have a list of objects which I want to perform an operation on. However I firstly need to divide the list into separate lists such that all items with the same parentID are in the same list, and then the operation is performed on each list separately (the reason being that the operation takes the parentID of the objects as a param...

structure member access - command line

hi, this may be a simple problem, but i am not able to figure it out. I have structure like this. struct emp { int empid; string fname; } emp e[10]; I have some data in e[10]. e[0].empid = 1 , e[0].fname = "tanenbaum" e[1].empid = 2 , e[1].fname = "knuth" ..... Now if i have given input command line like this: emp , empid ...

Database Structure for a Faceted Search

I am creating an eCommerce site that needs to have a faceted search tool so that customers can narrow down a product search via categories and classifications in the same style as ebuyer.com and Newegg.com (See left hand menus). I initially dived straight into designing a database that ended up similar to an EAV structure (I didn't know...

which data structure should be used for storing different tag values of XML after parsing it

I want to know a data structure for storing values of tags. My XML structure is : <personaldetails> <name>Michael</name> <age>28</age> <gender>Male</gender> <address>123 Streeet 7</address> <country>India</country> <pincode> 1234877</pincode> <contactno>35646445</contactno> <emailid>[email protected]</email...

Removal of items with duplicate data.

Hi I'm writing a function that removes the consecutive items with duplicate data . e.g For example, passing in the list ->a->b->c->c->a->b->b->b->a->null should result in ->a->b->c->a->b->a->null The list item definition and function declaration are given below struct litem { char data; litem* next; }; Mo code lo...