I am implementing a function to recursively reverse a linked-list, but getting seg-fault.
typedef struct _node {
int data;
struct _node *next;
} Node, *NodeP;
NodeP recursiveReverseList(NodeP first){
if(first == NULL) return NULL;
if(first->next == NULL) return first;
NodeP rest = recursiveReverseList(first->next);
r...
If I insert the letters A, G, I, and Y into a B-tree of order 4 (meaning 4 pointers and 3 elements in each node), I get the following B-tree.
G
/ \
A IY
Would it look any different if redistribution on insertion were used? How does redistribution on insertion work?
...
In Unit2 of my program i have the following code:
TValue = Record
NewValue,
OldValue,
SavedValue : Double;
end;
TData = Class(TObject)
Public
EconomicGrowth : TValue;
Inflation : TValue;
Unemployment : TValue;
CurrentAccountPosition : TValue;
AggregateSupply : TValue;
AggregateDemand : TValue;
ADGovernmentSpending ...
Is there any tricky way to implement a set data structure (a collection of unique values) in C? All elements in a set will be of the same type and there is a huge RAM memory.
As I know, for integers it can be done really fast'N'easy using value-indexed arrays. But I'd like to have a very general Set data type. And it would be nice if a...
Suppose I have a Java method that returns a HashMap object.
Because a LinkedHashMap is a subclass of HashMap, I can return a LinkedHashMap from this method just fine.
On the next "read" action (no adding/removing/modifying of K/V pairs), would iterating over the keys of the resulting method (which returns a HashMap) go in the same ord...
Given graph, how could i represent it using adj matrix?. I have read lots of tutorials, post, slides, etc but i cant get my head round it, i just need that little push.
...
How to count the number of right children in a binary tree?
This means that I only want the children marked as right.
Ex.
(Left | Right)
F(Root)
G | H
T U | I J
The right children would be U,H,and J.
What would be the algorithm to find these.
...
I'm trying to remove all of the leaves. I know that leaves have no children, this is what I have so far.
public void removeLeaves(BinaryTree n){
if (n.left == null && n.right == null){
n = null;
}
if (n.left != null)
removeLeaves(n.left);
if (n.right != null)
removeLeaves(n.right);
}
...
Hi,
I'm using fwrite() and fread() for the first time to write some data structures to disk and I have a couple of questions about best practices and proper ways of doing things.
What I'm writing to disk (so I can later read it back) is all user profiles inserted in a Graph structure. Each graph vertex is of the following type:
typede...
Hi, I need ideas for structuring and processing data with revisions.
For example, I have a database of objects (e.g. cars). Each object has a number of properties, which can be arbitrary, so there's no a set schema to describe these objects. These objects are probably saved as key-value pairs.
Now I need to change property of an object....
Linked-List: Mirror
Consider the following private class for a node of a singly-linked list of integers:
private class Node{
public int value;
public Node next;
}
A wrapper-class, called, ListImpl, contains a pointer, called start to the first node of a
linked list of Node.
Write an instance-method for ListImpl with the signature:
...
I'm trying to use Haskells Data.Heap module, but I'm incapable of even using it with integers. The only heap I've been capable of using is "empty", which does not take any arguments.
Later on I'll figure out how to instance for my needs, but for now I'd be glad if I was even able to test it with numbers.
...
If I have a list in python such as:
stuff = [1, 2, 3, 4, 5, 6, 7, 8, 9]
with length n (in this case 9) and I am interested in creating lists of length n/2 (in this case 4). I want all possible sets of n/2 values in the original list, for example:
[1, 2, 3, 4], [2, 3, 4, 5], ..., [9, 1, 2, 3]
is there some list comprehension c...
Hello,
I was looking for PHP TV guide scripts with it's Database structure.
Or at least the Database Structure by itself.
Any help or infomration would be really appreciated, I just don't want to start from scratch.
Thank you,
...
Hi
So here is my problem. I want to store 2-tuple (key, val) and want to perform following operations:
keys are strings and values are Integers
multiple keys can have same value
adding new tuples
updating any key with new value (any new value or updated value is greater than the previous one, like timestamps)
fetching all the keys wit...
I have a std::multiset which stores elements of class A. I have provided my own implementation of operator< for this class. My question is if I insert two equivalent objects into this multiset is their order guaranteed? For example, first I insert a object a1 into the set and then I insert an equivalent object a2 into this set. Can I exp...
I'm optimizing some code whose main bottleneck is running through and accessing a very large list of struct-like objects. Currently I'm using namedtuples, for readability. But some quick benchmarking using 'timeit' shows that this is really the wrong way to go where performance is a factor:
Named tuple with a, b, c:
>>> timeit("z = a...
I need a datastructure with the following properties:
It contains integer numbers.
Duplicates aren't allowed (that is, it stores at most one of any integer).
After it reaches the maximal size the first element is removed.
So if the capacity is 3, then this is how it would look when putting in it sequential numbers:
{}, {1}, {1, 2}, {1,...
I am looking to create a dictionary with 'roll-back' capabilities in python. The dictionary would start with a revision number of 0, and the revision would be bumped up only by explicit method call. I do not need to delete keys, only add and update key,value pairs, and then roll back. I will never need to 'roll forward', that is, when ro...
I have implemented a simple linux shell in c. Now, I am adding some features and one I immediately thought about was to be able to show the last commands with the up arrow.
Question 1:
However, I have no idea how to accomplish this. Do you?
Question 2:
Any comment on how to store the "history" commands are also appreciated. I suppose s...