Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Output example Please solve this java question with stacks,queue or dequeue. Don't use recursion: The LeafPile Problem Suppose you have an grid in which either

Output example

image text in transcribedPlease solve this java question with stacks,queue or dequeue. Don't use recursion:

The LeafPile Problem

Suppose you have an grid in which either grass or a leaf is in each cell of the grid (but not both). Your assignment is to determine the largest leaf pile on the map. Your algorithm may not utilize recursion to solve the problem. It must be purely iterative using either a stack or a queue.

The grid internally is represented like this

In which GRASS and LEAF are the enum values from Ground.java and this is a array.

For the purposes of shortness, GRASS will be represented by the period symbol . and LEAF will be represented by the tilde symbol ~ for the rest of the matrices in this document.

What constitutes a leaf pile?

A leaf is part of a pile if it touches another leaf in the four cardinal directions of north, east, south and west. Leaves that touch diagonally are not part of the pile. So, from the matrix above the piles are

Each pile is represented as a list of tuples that contain the coordinates of a leaf in the form of (row, column) or (y, x) such that y starts at the top and moves down while x starts at the left of the row and moves right.

As you can see, the pile with the most leaves is pile 2.

EXTRA HELPFUL CODE:

LEAFPILE.JAVA:

public class LeafPile { public static void main(String[] args) { Ground map[][] = new Ground[7][11]; generateRandomGround(map); printMap(map); System.out.println(largestLeafPile(map)); } /**********Student code here***************************/ private static int largestLeafPile(Ground map[][]) { } /***************End Student Code************************/ private static void printMap(Ground map[][]) { for (int r = 0; r  

GROUND.JAVA:

public enum Ground { GRASS('-'), LEAF('~'); private char symbol; private Ground(char value) { symbol = value; } public String toString() { return "" + symbol; } }

POSITION.JAVA:

public class Position { public final int row; public final int column; public Position(int row, int column) { this.row = row; this.column = column; } }
Map 1 Output - 4 Map 2 Output -6 Map 3 Map 1 Output - 4 Map 2 Output -6 Map 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago