answersLogoWhite

0

What else can I help you with?

Continue Learning about Engineering

Write an iterative function to search an element in a binary search tree?

_node* search (_node* head, _key key) { _node* node; for (node=head; node != NULL;;) { if (key == node->key) return node; else if (key < node.>key) node = node->left; else node = node->right; } return node; }


Insert a node into a doubly linked list at nth position where n is user defined in data structure in c source code?

# include < stdio.h > # include < stdlib.h > struct list { char info[20]; struct list *next; struct list *prev; }; struct list *new1,*node; void create(struct list *s,struct list *e) { char ch; node=s; printf("\nWant to create a node(y/n):"); ch=getche(); while (ch != 'n') { node->next = (struct list *) malloc(sizeof(struct list)); node->next->prev= node; node = node->next; printf("\n Enter the string value:- "); gets(node->info); node->next = e; e->prev=node; printf("\n Enter choice--'n' for break: "); ch = getche(); } } void displayL (struct list *s,struct list *e) { node = s->next; while (node!=e) { printf(" 0x%x--%s", node,node->info); node = node->next; } printf("\n"); } void displayR (struct list *e,struct list *s) { node = e->prev; while (node!=s) { printf(" 0x%x--%s", node,node->info); node = node->prev; } printf("\n"); } void insertA(struct list *s) { struct list *new1; int c=1,count; printf("\nEnter the location:"); scanf("%d",&count); fflush(stdin); new1 = (struct list *) malloc(sizeof(struct list)); printf("\nEnter the new value:"); gets(new1->info); node=s->next; while(node) { if(c==count) break; node=node->next; c++; } node->prev->next=new1; new1->prev=node->prev; new1->next=node; node->prev=new1; } void main() { struct list *start,*end; clrscr(); start=(struct list *) malloc(sizeof(struct list)); end=(struct list *) malloc(sizeof(struct list)); create(start,end); printf("\n Created list is as follows(L ->R)\n"); displayL(start,end); printf("\n Created list displayed from R->L\n"); displayR(end,start); printf("\nInserting a new location at user specified location\n"); insertA(start); printf("\n now the listfrom L ->R\n"); displayL(start,end); printf("\n list from R to L after insertion\n"); displayR(end,start); getch(); }


Algoritm for deleting the last element from a 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;


Is null node equal to leaf node?

No. A leaf node is a node that has no child nodes. A null node is a node pointer that points to the null address (address zero). Since a leaf node has no children, its child nodes are null nodes.


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 nodeprev->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); }

Related Questions

What is node and antinode?

Node is the point on the vibrating string with zero amplitude and antinode is the point where amplitude is the maximum. The distance between successive node will be half of the wavelength.


What is a node and a antinode?

A node 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.


What is antinode?

A node is a point along a standing wave where the wave has minimal amplitudeThe 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


What does antinode means?

A node 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


What part of standing wave antinode or node is present at the open end of a pipe?

The antinode is present at the open end of a pipe.


What is the difference between an antinode and a node in the context of wave patterns?

In wave patterns, an antinode is a point where the amplitude of the wave is at its maximum, while a node is a point where the amplitude is at its minimum or zero. Antinodes are where the wave is most intense, while nodes are where the wave is least intense.


What is nodes mean?

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.


What are the uses of nodes?

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.


What property of real resonance tubes slightly alters the position of this antinode?

The presence of open ends in real resonance tubes causes a slight alteration in the position of the antinode. This occurs because some of the sound waves are reflected at the open ends, leading to interference patterns that shift the location of the antinode.


What does one complete wave length depicted as a standing wave pattern look like?

A complete wavelength in a standing wave pattern consists of one node (point of no motion) and one antinode (point of maximum motion). This results in a pattern where the wave oscillates between constructive and destructive interference at these points along the medium. The amplitude of the wave is highest at the antinode and decreases to zero at the node.


What is an antinode?

in a wave there are some points which vibrate with maximum amplitude these points are called antinodes.pressure at\on these points is minimum hence they are also called pressure nodes.


What is a processing location on a network?

Node is a processing location on a network...