Conditions and Diseases

Database Programming

C Programming

Lymphatic System

# What is a node?

###### Wiki User

###### 2010-05-07 09:30:55

its an intersection point; where things meet

A node (knot) is a point **along a standing wave** where the

wave has minimal amplitude. The opposite of **a node** is an

antinode, a point where the amplitude of the standing wave is a

maximum. These occur midway between the nodes

## Related Questions

###### Asked in C Programming, DIY Projects, How To

### How to find the mirror image of a binary tree?

Refer to http://cslibrary.stanford.edu/110/BinaryTrees.html
void mirror(struct node* node) {
if (node==NULL) {
return;
}
else {
struct node* temp; // do the subtrees
mirror(node->left);
mirror(node->right); // swap the pointers in this node
temp = node->left;
node->left = node->right;
node->right = temp;
}
}

###### Asked in C Programming

### How do you insert a node into a doubly linked list?

To insert a node into a doubly linked list, create the following
function. The function accepts 4 arguments, a pointer to the list,
a pointer to the (new) node, and the nodes that will come before
and after it once inserted. If the previous node is NULL, the new
node becomes the head of the list. If the next node is NULL, the
new node becomes the tail of the list.
Node* insert (List* list, Node* node, Node* prev, Node* next)
{
if (!list !node) return 0;
node->next = next;
node->prev = prev;
if (!prev)
list->head = node;
else
prev->next = node;
if (!next)
list->tail = node;
else
next->prev = node;
return node;
}
With this function in place, you can simplify calls to it by
creating the following helper functions:
Node* insert_before (List* list, Node* node, Node* next) {
if (!next)
return insert (list, node, list->tail, 0);
else
return insert (list, mode, next->prev, next);
}
Node* insert_after (List* list, Node* node, Node* prev) {
if (!prev)
return insert (list, node, 0, list->head);
else
return insert (list, mode, prev, prev->next);
}

###### Asked in Computer Programming, Software Engineering

### How many pointers will have to be changed if a node is deleted from a linear linked list?

For a singly-linked list, only one pointer must be changed. If the
node about to be deleted (let's call it node for the sake of
argument) is the head of the list, then the head node pointer must
be changed to node->next. Otherwise, the node that comes
before the deleted node must change its next pointer
to node->next.
Note that given a singly-linked node has no knowledge of its
previous node, we must traverse the list from the head in order to
locate that particular node, unless the node is the head of the
list:
void remove (List* list, Node* node) {
if (!list !node) return; // sanity check!
if (list->head == node) {
list->head = node->next;
} else {
Node* prev = list->head;
while (prev->next != node) prev = prev->next; // locate the
node's previous node
prev->next = node->next;
}
}
Note that the remove function only removes the node from the list,
it does not delete it. This allows us to restore the node to its
original position, because the node itself was never modified (and
thus still refers to its next node in the list). So long as we
restore all removed nodes in the reverse order they were removed,
we can easily restore the list. In order to delete a node
completely, we simply remove it and then free it:
void delete (List* list, Node* node) {
if (!list !node) return; // sanity check!
remove (list, node);
free (node);
}
For a doubly-linked list, either two or four pointers must be
changed. If the node about to be deleted is the head node, then the
head node pointer must be changed to n->next and
n->next->prev must be changed to NULL, otherwise,
n->prev->next becomes n->next. In addition,
if the node about to be deleted is the tail node, then the tail
node pointer must be changed to n->prev and
n->prev->next must be changed to NULL, otherwise,
n->next->prev becomes n->prev.
Deletion from a doubly-linked list is generally quicker than
deletion from a singly linked list because a node in a
doubly-linked list knows both its previous node and its next node,
so there's no need to traverse the list to locate the previous node
to the one being deleted.
void remove (List* list, Node* node) {
if (!list !node) return; // sanity check!
if (list->head == node) {
list->head = node->next;
node->next->prev = NULL;
} else {
node->prev->next = node->next;
}
if (list->tail == node) {
list->tail = node->prev;
node->prev->next = NULL;
} else {
node->next->prev = node->prev;
}
}
Again, to physically delete the node we simply remove and then free
the node:
void delete (List* list, Node* node) {
if (!list !node) return; // sanity check!
remove (list, node);
free (node);
}

###### Asked in Computer Programming, C Programming

### Insert delete operations in Doubly Linked List?

Deleting a given node
if( node.next ) node.next.prev = node.prev;
if( node.prev ) node.prev.next = node.next;
if( head node ) tail = node.prev;
delete( node );
Inserting at the head
if( head ) head.prev = node;
node.next = head;
head = node;
Inserting at the tail
if( tail ) tail.next = node;
node.prev = tail;
tail = node;
Inserting after a given node
node.prev = given;
node.next = given.next;
if( given.next) given.next.prev = node;
given.next = node;
Inserting before a given node
node.next = given;
node.prev = given.prev;
if( given.prev ) given.prev.next = node;
given.prev = node;

###### Asked in Computer Programming, Database Programming, C Programming

### What is the algorithm to find largest node in a binary search tree?

Since a binary search tree is ordered to start with, to find the
largest node simply traverse the tree from the root, choosing only
the right node (assuming right is greater and left is less) until
you reach a node with no right node. You will then be at the
largest node.
for (node=root; node!= NULL&&node->right != NULL;
node=node->right);
This loop will do this. There is no body because all the work
is done in the control expressions.

###### Asked in Computer Programming, C Programming

### An algorithm to delete elements from a linked list?

Given a list and a node to delete, use the following
algorithm:
// Are we deleting the head node?
if (node == list.head)
{
// Yes -- assign its next node as the new head
list.head = node.next
}
else // The node is not the head node
{
// Point to the head node
prev = list.head
// Traverse the list to locate the node that comes immediately
before the one we want to delete
while (prev.next != node)
{
prev = prev.next;
}
end while
// Assign the node's next node to the previous node's next
node
prev.next = node.next;
}
end if
// Before deleting the node, reset its next node
node.next = null;
// Now delete the node.
delete node;

###### Asked in Computer Programming, Database Programming, C Programming

### What is a simple node?

In computer programming, a simple node is a structure that holds
two pointers. The first pointer refers to the data that is
indirectly associated with the node, while the other refers to the
next node in the sequence. Simple nodes are typically used in
forward lists (singly-linked lists) where we keep track of the head
node only. The last node in the list refers to NULL as there can be
no next node after the last node. We can insert new data into the
list knowing only the address of the data. A new node is
constructed which then refers to the data and to the current head
of the list. The new node then becomes the head of the list.
Insertions at the head are performed in constant time. Inserting
anywhere else in the list requires that we traverse the nodes
recursively, following each node's next pointer, starting from the
head, stopping at the node that should come after the new node.
That node then becomes the new node's next node (if the node
reaches the end of the list, the next node is NULL). Since we
traversed recursively, we can return the newly inserted node to the
caller, which can then be assigned to the caller's next node. All
other recursions simply return the node we traversed to, thus
leaving the caller's next node unchanged.
The following example shows a simple node implementation for an
ordered list of type int:
typedef struct Node_t { // a simple node
int* data;
Node_t* next;
} Node;
Node* insert (int* data, Node* node) { // insert data
if (!node *node->data > *data ) { // insertion point
reached (end recursions)
Node* pnode = malloc (sizeof (Node)); // create a new node
pnode->data = data; // attach the data
pnode->next = node; // refer to the next node (may be
NULL)
return pnode; // return the new node so the previous node can be
updated
}
// if we get this far, the given node comes before the new
data
// delegate to the next node, the return value is the new or
existing next node
node->next = insert (data, node->next);
return node; // return the node (it remains the previous node's
next node)
}
void print_all (Node* node) { // print the given node and all
that follow it
while (node) {
printf ("%d ", *node->data);
node = node->next;
}
}
Node* destroy_all (Node* node) // destroy the given node and all
that follow it while (node) {
Node* next = node->next; // refer to the next node (may be
NULL)
free (node->data); // release the current node's data
free (node); // release the node itself
node = next; // make the next node current (may be NULL)
}
return node; // always NULL
}
int main(void) { // The test program...
srand ((unsigned) time (NULL)); // seed a random number
generator
Node* head = NULL; // the head node of the list (initially NULL
for an empty list)
for (int i=0; i<10; ++i) { // insert 10 random integers
int* pint = malloc (sizeof (int)); // allocate a new integer on
the free store
if (!pint) break; // allocation failed, stop inserting!
*pint = rand () % 10; // assign a random integer value (range
0:9)
head = insert (pint, head); // insert the data (the return value
is the new or existing head)
}
print_all (head); // print all the nodes starting from the head
node
head = delete_all (head); // destroy all the nodes starting from
the head (returns NULL)
return 0;
}

###### Asked in C Programming, C++ Programming

### How do you insert a new node in a tree in c plus plus?

In order to insert a new node you must first determine where the
node will be inserted. For instance, in an unbalanced binary tree
(sorting tree), you will traverse from the root node, comparing its
data to the data you wish to insert. If the data to be inserted is
greater then you traverse to its right node, otherwise you traverse
to its left node. You repeat this process for each node you
traverse to until there is no node to traverse to. You then create
a new node for the data and assign the current node's left or right
pointer to the new node. That is, if the data is greater than the
current node, and the current node's right node is NULL, the new
node becomes the current node's right node. You then start at the
root to insert the next node.

###### Asked in Database Programming, C Programming

### What is parent node?

In programming, a parent node is any node that holds some
reference to a child node. The child node may itself be a parent
node.
A classic example of parent/child node usage is the binary tree,
where every node in the tree may hold a reference to up to 2
children. Nodes that have no children are known as leaf nodes.

###### Asked in C Programming, Backdoors, Computer Programming

### How do you you delete a node in singly linked list only pointer to that node is given in C?

Ya We can Do that actually.
1. Copy the content of the next node in to the node that has to
be deleted.
2. Assign the next pointer of the newly copied node of to the
next pointer of the node from the content has been copied.
3. Delete the node from the data has copied.
Another way of above problem is do a memcpy on current node from
next node. and delete the next node would be more faster and
optimized.

###### Asked in Computer Programming, C Programming, C++ Programming

### How do you insert a new node into circular linked list and where the new node will be inserted?

If the node is to be inserted in sorted order, you must traverse
the list from the head node or first node to locate the insertion
point. You then point the node to its next and previous nodes,
either side of the insertion point. Then update those nodes to
point at the new node.
That is, assuming node is to be inserted between
prev and next, you would use the following algorithm
(assuming every node has next and prev members):
node.next = next;
node.prev = prev;
next.prev = node;
prev.next = node;

###### Asked in C++ Programming

### How do you recursively reverse a singly linked list using c plus plus?

In this case recursion is not necessary, an iterative process is
more efficient.
Start by pointing at the head node. While this node has a next
node, detach its next node and insert that node at the head. Repeat
until the original head node has no next node. At that point the
head has become the tail and all the nodes are completely
reversed.
The following example shows how this can be implemented, where
the list object contains a head node (which may be NULL), and each
node has a next node. The tail node's next node is always NULL.
void reverse(list& lst)
{
if( node* p=lst.head )
{
while(p->next)
{
node* n=p.next; // point to the next node
p.next=n.next; // detach the next node
n.next=lst.head; // insert the detached node at the head
lst.head=n; // set the new head node
}
}
}