How to get XML node value in XSLT?

In Java, write the method add(int i, E x) to add a value x in a node after the first i existing data nodes?

  • This problem refers to a doubly linked node ; list with a head sentinel node and a tail sentinel. The data member of the head and tail nodes is set to null and these nodes are not used to store data. Assume the Node class is package myutil; class Node<E> { E data; Node prev, next; Node(E d) { data = d; } Node() { this(null); } } and the (partially shown) MyList class is package myutil; public class List<E> { private Node<E> head, tail; private int sz; public List() { head = new Node<E>(); tail = new Node<E>(); head.next = tail; head.prev = null; tail.next = null; tail.prev = head; sz = 0; } public void addLast(E x) {...} public void add(int i, E x) { ... } public E removeFront() {...} public E remove(int i) {...} public int size() { return sz; } } Write the method add(int i, E x) to add a value x in a node after the first i existing data nodes. For i = 0, add(0, x) would add x in a node after the head sentinel as the new first data node. If (i < 0) or (i > size()) add(int i, E x) should throw an IndexOutOfBoundsException.

  • Answer:

    Uhm I just started learning how to use nodes yesterday but I'm pretty sure you would do it like this. You said that the head and tail nodes are set to null but they are not o.0. And I am pretty sure you would need the head node. public void add( int i, E x){ Node<E> node = head; for (int b = 1; b < i; b++){ // goes through i amount of nodes node = head.next; } Node<E> temp = node.next; //temporarily stores what was supposed to come next node.next = new Node(x); //adds a new node where it should go node.next.next = temp; }

Igotaque... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.