Note that there are some explanatory texts on larger screens.

plurals
  1. POStack using double-linked list
    primarykey
    data
    text
    <p>Hey. I am assigned to do Stack using double-linked list and I faced a problem. I can't link to previous element (while I had no problems using one link).</p> <pre><code>class Node { Data data; Node previous; Node next; } class Data { int size; double price; boolean isOnOffer; char sex; String brand; Data(int size, double price, boolean isOnOffer, char sex, String brand){ this.size = size; this.price = price; this.isOnOffer = isOnOffer; this.sex = sex; this.brand = brand; } } class Stack { private static int sizeOfStack; private static Node topElement; public static boolean isEmpty() { return topElement == null; } public static void Initialize() { sizeOfStack = 0; topElement = null; } public static void Push(Data x) { Node oldElement = topElement; topElement = new Node(); topElement.data = x; topElement.next = oldElement; topElement.previous = null; //oldElement.previous = topElement; // &lt;----- problem here sizeOfStack++; } public static void Pop() { if (!isEmpty()){ topElement = topElement.next; // delete first node sizeOfStack--; } } public static void Top() { int size = topElement.data.size; double price = topElement.data.price; boolean isOnOffer = topElement.data.isOnOffer; char sex = topElement.data.sex; String brand = topElement.data.brand; System.out.println(size + " " + price + " " + isOnOffer + " " + sex + " " + brand); } public static void Kill() { } public static void Print() { } public static void main(String[] args){ Push(new Data(37, 155, false, 'F', "Nike")); Push(new Data(38, 140, true, 'F', "Reebok")); Push(new Data(35, 160.99, false, 'F', "Converse")); Push(new Data(35, 20.99, true, 'F', "Inkaras")); Pop(); Pop(); Top(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload