Skip to content

Commit aba9dfa

Browse files
panaweecthuva4
authored andcommitted
Update README.md and manage file to language folder (thuva4#440)
* Update README.md * Create folder and move file to language folder
1 parent dd0f055 commit aba9dfa

File tree

9 files changed

+273
-30
lines changed

9 files changed

+273
-30
lines changed

FloodFill/Java/FloodFill.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import java.awt.Color;
2+
import java.awt.Graphics;
3+
import java.awt.event.KeyEvent;
4+
import java.awt.event.KeyListener;
5+
6+
import javax.swing.JFrame;
7+
8+
public class FloodFill extends JFrame{
9+
private int myPixel = 25;
10+
private int loops = 1;
11+
12+
public FloodFill() {
13+
KeyListener listener = new MyKeyListener();
14+
addKeyListener(listener);
15+
setFocusable(true);
16+
}
17+
18+
19+
private void drawGrid(Graphics g){
20+
g.setColor(Color.white);
21+
for(int i=0; i < 500; i+=myPixel){
22+
g.drawLine(0, i, 500, i);
23+
g.drawLine(i, 0, i, 500);
24+
}
25+
}
26+
27+
private Color[][] fill(int x, int y, int loops){
28+
Color[][] toFill = new Color[20][20];
29+
toFill = floodFill(x, y, toFill, loops);
30+
31+
return toFill;
32+
}
33+
34+
private Color[][] floodFill(int x, int y, Color[][] toFill, int loops){
35+
if(loops <= 0){
36+
return toFill;
37+
}
38+
if(x < 3 || x >= 17 || y < 3 || y >= 17){
39+
return toFill;
40+
}
41+
if(toFill[x][y] != null && (!toFill[x][y].equals(Color.red))){
42+
return toFill;
43+
}
44+
else{
45+
toFill[x][y] = Color.red;
46+
toFill = floodFill(x+1, y, toFill, loops-1);
47+
toFill = floodFill(x, y+1, toFill, loops-1);
48+
toFill = floodFill(x-1, y, toFill, loops-1);
49+
toFill = floodFill(x, y-1, toFill, loops-1);
50+
}
51+
return toFill;
52+
}
53+
54+
private void drawFill(Graphics g, Color[][] toFill){
55+
for(int i=0; i < toFill.length; i++){
56+
for(int j=0; j< toFill[i].length; j++){
57+
g.setColor(toFill[i][j]);
58+
g.fillRect(i*myPixel, j*myPixel, myPixel, myPixel);
59+
g.setColor(Color.black);
60+
}
61+
}
62+
}
63+
64+
public void paint(Graphics g){
65+
Color[][] toFill = fill(10,10,loops);
66+
drawFill(g, toFill);
67+
drawGrid(g);
68+
repaint();
69+
}
70+
71+
public static void main(String[] args){
72+
FloodFill frame = new FloodFill();
73+
frame.setTitle("Flood Fill");
74+
frame.setSize(500,500);
75+
frame.setVisible(true);
76+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
77+
}
78+
public class MyKeyListener implements KeyListener{
79+
@Override
80+
public void keyPressed(KeyEvent arg0) {
81+
}
82+
83+
@Override
84+
public void keyReleased(KeyEvent arg0) {
85+
if(arg0.getKeyCode() == 39){
86+
loops++;
87+
}
88+
if(arg0.getKeyCode() == 37){
89+
loops--;
90+
}
91+
System.out.println(loops);
92+
}
93+
94+
@Override
95+
public void keyTyped(KeyEvent arg0) {
96+
// TODO Auto-generated method stub
97+
98+
}
99+
}
100+
}

FloodFill/Python/floodfill.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def fill(data, start_coords, fill_value):
2+
"""
3+
Flood fill algorithm
4+
5+
Parameters
6+
----------
7+
data : (M, N) ndarray of uint8 type
8+
Image with flood to be filled. Modified inplace.
9+
start_coords : tuple
10+
Length-2 tuple of ints defining (row, col) start coordinates.
11+
fill_value : int
12+
Value the flooded area will take after the fill.
13+
14+
Returns
15+
-------
16+
None, ``data`` is modified inplace.
17+
"""
18+
xsize, ysize = data.shape
19+
orig_value = data[start_coords[0], start_coords[1]]
20+
21+
stack = set(((start_coords[0], start_coords[1]),))
22+
if fill_value == orig_value:
23+
raise ValueError("Filling region with same value "
24+
"already present is unsupported. "
25+
"Did you already fill this region?")
26+
27+
while stack:
28+
x, y = stack.pop()
29+
30+
if data[x, y] == orig_value:
31+
data[x, y] = fill_value
32+
if x > 0:
33+
stack.add((x - 1, y))
34+
if x < (xsize - 1):
35+
stack.add((x + 1, y))
36+
if y > 0:
37+
stack.add((x, y - 1))
38+
if y < (ysize - 1):
39+
stack.add((x, y + 1))

InsertionSort/C/InsertionSort.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// including liberary
2+
#include <stdio.h>
3+
4+
/*
5+
the algo goes here
6+
*/
7+
void Sort_Array(int arr[], int size) // it will accept interger type array and size of the array
8+
{
9+
// local variable defination
10+
int i, key, j;
11+
for (i = 1; i < size; i++)
12+
{
13+
key = arr[i]; // the i th value
14+
j = i-1; // j is for processing from back
15+
16+
/* Move elements of arr[0..i-1], that are
17+
greater than key, to one position ahead
18+
of their current position */
19+
while (j >= 0 && arr[j] > key) // loop will work till j th value of array is greater than i th value of array and j >= 0
20+
{
21+
arr[j+1] = arr[j];
22+
j--;
23+
}
24+
arr[j+1] = key;
25+
}
26+
}
27+
28+
/*
29+
MAIN FUNCTION
30+
*/
31+
int main() {
32+
// declaring the variable
33+
int size; // size is the array length
34+
int i; // i is for iterations
35+
printf("enter the size of array ");
36+
scanf("%d",&size); // getting size
37+
int array[size]; // declaring array of size entered by the user
38+
39+
// getting value from the user
40+
printf("\nenter values in the array\n");
41+
for (i = 0; i < size; i++) {scanf("%d", &array[i]); }
42+
43+
// printing the original array
44+
printf("\noriginal array -> ");
45+
for (i = 0; i < size; i++) { printf("%d ", array[i]); }
46+
47+
// sorting the array
48+
Sort_Array(array, size);
49+
50+
// printing the sorted array
51+
printf("\nsorted array -> ");
52+
for (i = 0; i < size; i++) { printf("%d ", array[i]); }
53+
54+
return 0;
55+
}
56+

QuickSort/C/QuickSort.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include<stdio.h>
2+
void quicksort(int number[25],int first,int last){
3+
int i, j, pivot, temp;
4+
5+
if(first<last){
6+
pivot=first;
7+
i=first;
8+
j=last;
9+
10+
while(i<j){
11+
while(number[i]<=number[pivot]&&i<last)
12+
i++;
13+
while(number[j]>number[pivot])
14+
j--;
15+
if(i<j){
16+
temp=number[i];
17+
number[i]=number[j];
18+
number[j]=temp;
19+
}
20+
}
21+
22+
temp=number[pivot];
23+
number[pivot]=number[j];
24+
number[j]=temp;
25+
quicksort(number,first,j-1);
26+
quicksort(number,j+1,last);
27+
28+
}
29+
}
30+
31+
int main(){
32+
int i, count, number[25];
33+
34+
printf("How many elements are u going to enter?: ");
35+
scanf("%d",&count);
36+
37+
printf("Enter %d elements: ", count);
38+
for(i=0;i<count;i++)
39+
scanf("%d",&number[i]);
40+
41+
quicksort(number,0,count-1);
42+
43+
printf("Order of Sorted elements: ");
44+
for(i=0;i<count;i++)
45+
printf(" %d",number[i]);
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)