Threads
java ( 81351 ) - java ( 81352 ) stack: com.thealgorithms.dynamicprogramming.BoundaryFill.main(BoundaryFill.java:72)
package com.thealgorithms.dynamicprogramming;
/**
* Java program for Boundary fill algorithm.
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
*/
public final class BoundaryFill {
private BoundaryFill() {
}
/**
* Get the color at the given co-odrinates of a 2D image
*
* @param image The image to be filled
* @param xCoordinate The x co-ordinate of which color is to be obtained
* @param yCoordinate The y co-ordinate of which color is to be obtained
*/
public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
return image[xCoordinate][yCoordinate];
}
/**
* Put the color at the given co-odrinates of a 2D image
*
* @param image The image to be filed
* @param xCoordinate The x co-ordinate at which color is to be filled
* @param yCoordinate The y co-ordinate at which color is to be filled
*/
public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int newColor) {
image[xCoordinate][yCoordinate] = newColor;
}
/**
* Fill the 2D image with new color
*
* @param image The image to be filed
* @param xCoordinate The x co-ordinate at which color is to be filled
* @param yCoordinate The y co-ordinate at which color is to be filled
* @param newColor The new color which to be filled in the image
* @param boundaryColor The old color which is to be replaced in the image
*/
public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
if (xCoordinate >= 0 && yCoordinate >= 0 && getPixel(image, xCoordinate, yCoordinate) != newColor && getPixel(image, xCoordinate, yCoordinate) != boundaryColor) {
putPixel(image, xCoordinate, yCoordinate, newColor);
boundaryFill(image, xCoordinate + 1, yCoordinate, newColor, boundaryColor);
boundaryFill(image, xCoordinate - 1, yCoordinate, newColor, boundaryColor);
boundaryFill(image, xCoordinate, yCoordinate + 1, newColor, boundaryColor);
boundaryFill(image, xCoordinate, yCoordinate - 1, newColor, boundaryColor);
boundaryFill(image, xCoordinate + 1, yCoordinate - 1, newColor, boundaryColor);
boundaryFill(image, xCoordinate - 1, yCoordinate + 1, newColor, boundaryColor);
boundaryFill(image, xCoordinate + 1, yCoordinate + 1, newColor, boundaryColor);
boundaryFill(image, xCoordinate - 1, yCoordinate - 1, newColor, boundaryColor);
}
}
/**
* This method will print the 2D image matrix
*
* @param image The image to be printed on the console
*/
public static void printImageArray(int[][] image) {
for (int i = 0; i < image.length; i++) {
for (int j = 0; j < image[0].length; j++) {
System.out.print(image[i][j] + " ");
}
System.out.println();
}
}
// Driver Program
public static void main(String[] args) {
// Input 2D image matrix
int[][] image = {
{0, 0, 0, 0, 0, 0, 0},
{0, 3, 3, 3, 3, 0, 0},
{0, 3, 0, 0, 3, 0, 0},
{0, 3, 0, 0, 3, 3, 3},
{0, 3, 3, 3, 0, 0, 3},
{0, 0, 0, 3, 0, 0, 3},
{0, 0, 0, 3, 3, 3, 3},
};
boundaryFill(image, 2, 2, 5, 3);
/* Output ==>
* 0 0 0 0 0 0 0
0 3 3 3 3 0 0
0 3 5 5 3 0 0
0 3 5 5 3 3 3
0 3 3 3 5 5 3
0 0 0 3 5 5 3
0 0 0 3 3 3 3
* */
// print 2D image matrix
printImageArray(image);
}
}
Variables All
| No. | From | Name | Value |
|---|---|---|---|
| 1 | 72 | args | [Ljava.lang.String;@7852e922 |
| END | 0 | 0 | 0 |
| Process Filter | Thread Filter |
|---|---|
| 81351 java | 81352 java |
| No. | PN | PID | TID | TN | Message |
|---|---|---|---|---|---|
| 1 | java | 81351 | 81352 | java | 0 |
| 2 | java | 81351 | 81352 | java | 0 |
| 3 | java | 81351 | 81352 | java | 0 |
| 4 | java | 81351 | 81352 | java | 0 |
| 5 | java | 81351 | 81352 | java | 0 |
| 6 | java | 81351 | 81352 | java | 0 |
| 7 | java | 81351 | 81352 | java | 0 |
| 8 | java | 81351 | 81352 | java | 0 |
| 9 | java | 81351 | 81352 | java | 3 |
| 10 | java | 81351 | 81352 | java | 3 |
| 11 | java | 81351 | 81352 | java | 3 |
| 12 | java | 81351 | 81352 | java | 3 |
| 13 | java | 81351 | 81352 | java | 0 |
| 14 | java | 81351 | 81352 | java | 0 |
| 15 | java | 81351 | 81352 | java | 0 |
| 16 | java | 81351 | 81352 | java | 3 |
| 17 | java | 81351 | 81352 | java | 5 |
| 18 | java | 81351 | 81352 | java | 5 |
| 19 | java | 81351 | 81352 | java | 3 |
| 20 | java | 81351 | 81352 | java | 0 |
| 21 | java | 81351 | 81352 | java | 0 |
| 22 | java | 81351 | 81352 | java | 0 |
| 23 | java | 81351 | 81352 | java | 3 |
| 24 | java | 81351 | 81352 | java | 5 |
| 25 | java | 81351 | 81352 | java | 5 |
| 26 | java | 81351 | 81352 | java | 3 |
| 27 | java | 81351 | 81352 | java | 3 |
| 28 | java | 81351 | 81352 | java | 3 |
| 29 | java | 81351 | 81352 | java | 0 |
| 30 | java | 81351 | 81352 | java | 3 |
| 31 | java | 81351 | 81352 | java | 3 |
| 32 | java | 81351 | 81352 | java | 3 |
| 33 | java | 81351 | 81352 | java | 5 |
| 34 | java | 81351 | 81352 | java | 5 |
| 35 | java | 81351 | 81352 | java | 3 |
| 36 | java | 81351 | 81352 | java | 0 |
| 37 | java | 81351 | 81352 | java | 0 |
| 38 | java | 81351 | 81352 | java | 0 |
| 39 | java | 81351 | 81352 | java | 3 |
| 40 | java | 81351 | 81352 | java | 5 |
| 41 | java | 81351 | 81352 | java | 5 |
| 42 | java | 81351 | 81352 | java | 3 |
| 43 | java | 81351 | 81352 | java | 0 |
| 44 | java | 81351 | 81352 | java | 0 |
| 45 | java | 81351 | 81352 | java | 0 |
| 46 | java | 81351 | 81352 | java | 3 |
| 47 | java | 81351 | 81352 | java | 3 |
| 48 | java | 81351 | 81352 | java | 3 |
| 49 | java | 81351 | 81352 | java | 3 |
| END | 0 | 0 | 0 | 0 | 0 |
×
Functions and Shortcuts
| No. | Function | Shortcuts | Description |
|---|---|---|---|
| 1 | GB | Alt + LEFT, Alt + A | Go Backward |
| 2 | GF | Alt + RIGHT, Alt + D | Go Foreward |
| 3 | PPE | Alt + UP, Alt + W | Previous Process End |
| 4 | NPS | Alt + DOWN, Alt + S | Next Process Start |
| 5 | PB | Ctrl + LEFT, Ctrl + A | current Process Backward |
| 6 | PF | Ctrl + RIGHT, Ctrl + D | current Process Foreward |
| 7 | PPTE | Ctrl + UP, Ctrl + W | go to current Process's Previous Thread's End |
| 8 | PNTS | Ctrl + DOWN, Ctrl + S | go to current Process's Next Thread's Start |
| 9 | TB | LEFT, A | current Thread Backward |
| 10 | TF | RIGHT, D | current Thread Foreward |
| 11 | LU | UP, W | go Line Up of current code block in current thread |
| 12 | LD | DOWN, S | go Line Down of current code block in current thread |
| 13 | LP | Shift + UP, Shift + W | go to the occurrence of current line in Previous Loop |
| 14 | LD | Shift + DOWN, Shift + S | go to the occurrence of current line in Next Loop |
| 15 | BS | Home | go to code Block Start |
| 16 | BE | End | go to code Block End |
| Project: | Alg-Java |
| Update: | 20240824 |
| Commit: | a7cd97d7 |
| Source Code: | dynamicprogramming.BoundaryFill |
| BuildTool: | Java17 |
| Compiler: | Java17 |
| Runtime: | Openjdk17 |
| System: | MySystemD |
| Kernel: | Linux5.10.211 |
| Cpu: | Intel:Corei7-7700K |
| Machine: | AwesomeMachine |