{"id":1225,"date":"2017-07-08T16:07:11","date_gmt":"2017-07-08T16:07:11","guid":{"rendered":"http:\/\/www.testingdocs.com\/questions\/?p=1225"},"modified":"2021-03-21T06:48:56","modified_gmt":"2021-03-21T06:48:56","slug":"design-a-stack-to-separate-positive-and-negative-values","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/design-a-stack-to-separate-positive-and-negative-values\/","title":{"rendered":"Design a Stack to separate positive and negative values"},"content":{"rendered":"<h3>Problem Statement<\/h3>\n<p>Design a Stack with all standard functions and an additional method that moves all positive values from a stack into a second stack and all the negative values into a third stack.<\/p>\n<p>Condition for the additional method to be met:<br \/>\nThe values moved into the second and third stacks must maintain their original order from the first stack as shown in the below example picture. Create a Demo class to demonstrate the example output shown in the picture.<\/p>\n<h3>Picture and Sample Output<\/h3>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2341\" src=\"http:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Stacks-with-positive-and-negative-numbers.png\" alt=\"Stacks with positive and negative numbers\" width=\"1091\" height=\"592\" title=\"\"><\/p>\n<p>&nbsp;<\/p>\n<p>Solution is left as an exercise for the reader.<\/p>\n<h3>Hints:<\/h3>\n<p>Consider a method signature for the additional method as:<\/p>\n<p>&nbsp;<\/p>\n<pre>public void filterValues(Stack stack2,Stack stack3) {\r\n    .....\r\n}\r\n\r\n<\/pre>\n<p>Use a print method to print the elements of different stacks.<\/p>\n<p>&nbsp;<\/p>\n<pre>public void print(String stackName) { \r\n    .... \r\n}<\/pre>\n<p>&nbsp;<\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-1225\" data-postid=\"1225\" class=\"themify_builder_content themify_builder_content-1225 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Problem Statement Design a Stack with all standard functions and an additional method that moves all positive values from a stack into a second stack and all the negative values into a third stack. Condition for the additional method to be met: The values moved into the second and third stacks must maintain their original [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1225","post","type-post","status-publish","format-standard","hentry","category-automation","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=1225"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1225\/revisions"}],"predecessor-version":[{"id":19746,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1225\/revisions\/19746"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=1225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=1225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=1225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}