{"id":54717,"date":"2021-09-30T16:50:03","date_gmt":"2021-09-30T16:50:03","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/09\/30\/stack-implementation-with-linked-list-in-java\/"},"modified":"2021-09-30T16:50:03","modified_gmt":"2021-09-30T16:50:03","slug":"stack-implementation-with-linked-list-in-java","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/09\/30\/stack-implementation-with-linked-list-in-java\/","title":{"rendered":"Stack Implementation With Linked List in Java"},"content":{"rendered":"<p>I Need help to understand How I can Implement Stack With Linked List in Java. This is for my assignment and I got stuck here, <br \/>I have to Implement the interface DStack, which has the methods push(), pop(), peek(), and isEmpty() in our LinkedList.java file. <br \/>Code Start &#8212;&#8212;-&gt; <br \/>public class ListStack implements DStack{ <br \/>private Node head; <br \/>private int size; <br \/>private class Node{ <br \/> double d; <br \/> Node next; <br \/> public Node(){ <br \/> head = null; <br \/> next = null; <br \/> } <br \/> public Node(double data){ <br \/> d = data; <br \/> } <br \/>} <br \/>public boolean isEmpty() { <br \/> return (head == null); <br \/>} <br \/>@Override <br \/>public void push(double d) { <br \/> if(!isEmpty()){ <br \/> Node newHead = new Node(d); <br \/> newHead.next = head; <br \/> head = newHead; <br \/> size ; <br \/> } <br \/> else <br \/> throw new EmptyStackException(); \/\/To change body of generated methods, choose Tools | Templates. <br \/>} <br \/>@Override <br \/>public double pop() { <br \/> if(!isEmpty()){ <br \/> double d = head.d; <br \/> head = head.next; <br \/> size&#8211;; <br \/> return d; <br \/> } <br \/> else <br \/> throw new EmptyStackException(); \/\/To change body of generated methods, choose Tools | Templates. <br \/>} <br \/>@Override <br \/>public double peek() { <br \/> if(!isEmpty()){ <br \/> return head.d; <br \/> } <br \/> else <br \/> throw new EmptyStackException(); \/\/To change body of generated methods, choose Tools | Templates. <br \/>} <br \/>Code End &lt;&#8212;&#8212;&#8212;&#8212;&#8212; <br \/>Can someone help me to understand If I am doing the push() and pop() methods correctly? <br \/>I was taking reference from this article. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I Need help to understand How I can Implement Stack With Linked List in Java. This is for my assignment and I got stuck here, I have to Implement the interface DStack, which has the methods push(), pop(), peek(), and isEmpty() in our LinkedList.java file. Code Start &#8212;&#8212;-&gt; public class ListStack implements DStack{ private Node [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-54717","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/54717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=54717"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/54717\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=54717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=54717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=54717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}