1. ## Constraint

Can somebody help me using constraint in linked list?
Actually I don't know about constraint. May be you can tell me clearly.
Thank you

2. Maybe you could ask your question more clearly.

From an english language dictionary, the applicable definition is simple: "Constraint (n): limitation or restriction"

In the context of linked lists, constraints would often be related to complexity of operations on the list. For example, the time to find the first or last element might be amortised constant (i.e. independent of the number of nodes in the list). The time to insert a new node might also be amortised constant. The average time to find a particular node in the list might linear with size of the list (i.e. double the number of nodes in the list, then the average time to find a particular node also doubles).

Constraints might also be relevant to the overhead associated with adding a node to the list. For example, when adding a new node to a linked list of ints, the node will include an int as well as other overhead related to managing the list. The amount of this overhead per node depends on the type of list (e.g. a doubly linked list often has twice the memory overhead per node as a singly linked list, but some operations on a list might be faster).

Since there is more than one type of linked list, each one probably is subject to a different set of constraints. I've already mentioned the memory overhead - the constraint on memory usage for a single linked list differs from the constraint for a double linked list.

There are also constraints related to quality of implementation or correctness of code that affects the list. For example, when inserting a new node into a list X, a constraint might that no other list (say Y) would be affected.

But, then, your question is unclear. That imposes a constraint on the quality of my answer - the only answer I can give relies on a guess about what you mean. Because of that constraint, I may have inadvertently given a completely incorrect answer.

3. So, to declare a constraint, we can use constant?

4. Originally Posted by Uli
So, to declare a constraint, we can use constant?
There are programming languages where you can declare a constraint (eg specialized languages for doing linear programming). C is not one of them.

If you mean something more like a parameter ("Today I want the value of gravity to be 6.98") then a constant may be appropriate there. If you want to specify a range, then that falls under setting your algorithm up correctly and nothing to do with the language itself.

5. oh, I see...
Thank you very much.

Popular pages Recent additions