Skip to content

Commit ae93f8b

Browse files
authored
Merge branch 'master' into patch-1
2 parents a1c447e + c4dfa69 commit ae93f8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+389185
-1217
lines changed

Assembly.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1+
//creating the class assembly
2+
3+
package javacodes;
14

25
import java.util.*;
36

47
public class Assembly {
58

69
public static void main(String args[]) {
710
Scanner in = new Scanner(System.in);
8-
Map<String, Integer> vars = new HashMap<String, Integer>();
9-
Map<String, Integer> labels = new HashMap<String, Integer>();
10-
Map<Integer, Integer> endif = new HashMap<Integer, Integer>();
11-
Map<Integer, Integer> loop = new HashMap<Integer, Integer>();
11+
Map<String, Integer> vars = new HashMap<>();
12+
Map<String, Integer> labels = new HashMap<>();
13+
Map<Integer, Integer> endif = new HashMap<>();
14+
Map<Integer, Integer> loop = new HashMap<>();
1215
Stack ifs = new Stack();
1316
Stack fors = new Stack();
1417
String temp;
15-
ArrayList<String> code = new ArrayList<String>();
18+
ArrayList<String> code = new ArrayList<>();
1619
while (true) {
1720
temp = in.nextLine();
18-
if(temp.equals("###")){
21+
if (temp.equals("###")) {
1922
break;
2023
}
2124
code.add(temp);
22-
25+
2326
}
2427
//temp = in.nextLine();
2528
//code.add(temp);
2629
int l = code.size();
2730
String comp[];
2831
int a, b, i;
29-
a=b=i=0;
32+
a = b = i = 0;
3033
for (i = 0; i < l; i++) {
3134
comp = code.get(i).split(" ");
3235
switch (comp[0]) {
@@ -84,12 +87,12 @@ public static void main(String args[]) {
8487
break;
8588
case "END":
8689
endif.put((Integer) ifs.pop(), i);
87-
if(!fors.empty()){
88-
fors.pop();
90+
if (!fors.empty()) {
91+
fors.pop();
8992
}
9093
break;
9194
case "CONTINUE":
92-
loop.put(i, (Integer) fors.pop()-1);
95+
loop.put(i, (Integer) fors.pop() - 1);
9396
break;
9497
default:
9598
i = i; //do nothing
@@ -140,15 +143,17 @@ public static void main(String args[]) {
140143
break;
141144
case "IF":
142145
if (comp[1].compareTo("a") >= 0 && comp[1].compareTo("z") <= 0) {
143-
if (vars.containsKey(comp[1])) {
144-
a = vars.get(comp[1]);
145-
}} else {
146+
if (vars.containsKey(comp[1])) {
147+
a = vars.get(comp[1]);
148+
}
149+
} else {
146150
a = Integer.parseInt(comp[1]);
147151
}
148152
if (comp[2].compareTo("a") >= 0 && comp[2].compareTo("z") <= 0) {
149-
if (vars.containsKey(comp[2])) {
150-
b = vars.get(comp[2]);
151-
}} else {
153+
if (vars.containsKey(comp[2])) {
154+
b = vars.get(comp[2]);
155+
}
156+
} else {
152157

153158
b = Integer.parseInt(comp[2]);
154159
}
@@ -163,8 +168,8 @@ public static void main(String args[]) {
163168
case "LABEL":
164169
break;
165170
case "END":
166-
if(!ifs.empty()){
167-
ifs.pop();
171+
if (!ifs.empty()) {
172+
ifs.pop();
168173
}
169174
break;
170175
case "CONTINUE":

DigitalMax.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// findind the digital max
21
package javacodes;
32

43
import java.util.*;
@@ -7,36 +6,46 @@ public class DigitalMax {
76

87
public static void main(String[] agrs)
98
{
10-
Scanner in=new Scanner(System.in);
9+
Scanner in =new Scanner(System.in);
10+
1111
//User will enter a number
1212
System.out.println("Enter a number :");
1313

1414
int n=in.nextInt();
1515

16+
//set 'temp', 'a' counter to 0
1617
int temp=0,a;
1718

18-
19+
//initializing the array
1920
int[] arr={8,9,8,9,9,9,8,9,8,9};
2021

22+
//if user enters a positive figure
2123
while(n>0)
2224

2325
{
24-
a=n%10;
26+
//remainder of 'a'
27+
a=n%10;
2528

29+
//get array value accordingly of it's index
2630
temp=temp*10+arr[a];
2731

2832
n=n/10;
2933
}
34+
35+
//declaring answer variable
3036
int ans=0;
3137

3238
while(temp>0)
3339
{
40+
//calculating remainder of a
3441
a=temp%10;
3542

43+
//calculating answer
3644
ans=ans*10+a;
3745

3846
temp=temp/10;
3947
}
48+
//answer prompt
4049
System.out.println("Maximum no:"+" "+ans);
4150
}
42-
}
51+
}

Dijkstra.java

Lines changed: 65 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,91 @@
11
/*
22
this program is used to find minimum distance between two vertices while traversing all available vertices.
3-
*/
3+
*/
44
package javacodes;
55

66
import java.util.*;
7-
7+
88
public class Dijkstra {
9-
9+
1010
static int V;
11-
12-
int minDistance(int dist[], Boolean que[])
13-
{
14-
15-
int min = Integer.MAX_VALUE, index=-1;
16-
17-
for (int i = 0; i < V; i++)
18-
19-
if (que[i] == false && dist[i] <= min)
20-
{
11+
12+
int minDistance(int dist[], Boolean que[]) {
13+
14+
int min = Integer.MAX_VALUE, index = -1;
15+
16+
for (int i = 0; i < V; i++) {
17+
if (que[i] == false && dist[i] <= min) {
2118
min = dist[i];
22-
19+
2320
index = i;
2421
}
25-
22+
}
23+
2624
return index;
2725
}
28-
29-
30-
void printSolution(int dist[], int n)
31-
{
26+
27+
void printSolution(int dist[], int n) {
3228
System.out.println("Vertex Distance from Source");
33-
34-
for (int i = 0; i < V; i++)
35-
36-
System.out.println(i+" \t\t "+dist[i]);
29+
30+
for (int i = 0; i < V; i++) {
31+
System.out.println(i + " \t\t " + dist[i]);
32+
}
3733
}
38-
39-
40-
void dijkstra(int graph[][], int src)
41-
{
42-
int dist[] = new int[V];
43-
34+
35+
void dijkstra(int graph[][], int src) {
36+
int dist[] = new int[V];
37+
4438
Boolean que[] = new Boolean[V];
45-
46-
47-
for (int i = 0; i < V; i++)
48-
{
39+
40+
for (int i = 0; i < V; i++) {
4941
dist[i] = Integer.MAX_VALUE;
50-
42+
5143
que[i] = false;
5244
}
53-
54-
55-
dist[src] = 0; /* Starting distance is zero */
56-
57-
58-
for (int count = 0; count < V-1; count++)
59-
{
60-
45+
46+
dist[src] = 0;
47+
/* Starting distance is zero */
48+
49+
50+
for (int count = 0; count < V - 1; count++) {
51+
6152
int u = minDistance(dist, que);
62-
63-
53+
6454
que[u] = true;
65-
66-
67-
for (int i = 0; i < V; i++)
68-
69-
70-
if (!que[i] && graph[u][i]!=0 &&
71-
72-
dist[u] != Integer.MAX_VALUE &&
73-
74-
dist[u]+graph[u][i] < dist[i])
75-
76-
dist[i] = dist[u] + graph[u][i];
77-
55+
56+
for (int i = 0; i < V; i++) {
57+
if (!que[i] && graph[u][i] != 0
58+
&& dist[u] != Integer.MAX_VALUE
59+
&& dist[u] + graph[u][i] < dist[i]) {
60+
dist[i] = dist[u] + graph[u][i];
61+
}
62+
}
63+
7864
}
79-
80-
65+
8166
printSolution(dist, V);
8267
}
83-
84-
85-
public static void main (String[] args)
86-
{
87-
Scanner in=new Scanner(System.in);
88-
89-
System.out.println("Number of vertices:"); /* print the total numbers of vertices */
90-
91-
V=in.nextInt();
92-
93-
int [][]graph = new int[V][V];
94-
95-
System.out.println("Rows and Column of matrix:");
96-
97-
for(int i=0;i<V;i++)
98-
{
99-
for(int j=0;j<V;j++)
100-
101-
graph[i][j]=in.nextInt();
102-
}
103-
Dijkstra ob=new Dijkstra(); /* create new object of Dijkstra */
104-
68+
69+
public static void main(String[] args) {
70+
Scanner in = new Scanner(System.in);
71+
72+
System.out.println("Number of vertices:");
73+
/* print the total numbers of vertices */
74+
75+
V = in.nextInt();
76+
77+
int[][] graph = new int[V][V];
78+
79+
System.out.println("Rows and Column of matrix:");
80+
81+
for (int i = 0; i < V; i++) {
82+
for (int j = 0; j < V; j++) {
83+
graph[i][j] = in.nextInt();
84+
}
85+
}
86+
Dijkstra ob = new Dijkstra();
87+
/* create new object of Dijkstra */
88+
10589
ob.dijkstra(graph, 0);
10690
}
10791
}

0 commit comments

Comments
 (0)