Rahul/multidimensional/pr3 (#6040)
* Making examples simple * Changing variable names * Modificatons in naming * Giving extra spaces
This commit is contained in:
parent
9053ecd128
commit
0d5483e1bf
@ -6,11 +6,11 @@ public class ArrayListOfArrayList {
|
|||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
|
|
||||||
int numVertices = 3;
|
int vertexCount = 3;
|
||||||
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(numVertices);
|
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(vertexCount);
|
||||||
|
|
||||||
//Initializing each element of ArrayList with ArrayList
|
//Initializing each element of ArrayList with ArrayList
|
||||||
for(int i=0; i< numVertices; i++) {
|
for(int i = 0; i< vertexCount; i++) {
|
||||||
graph.add(new ArrayList<Integer>());
|
graph.add(new ArrayList<Integer>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +22,13 @@ public class ArrayListOfArrayList {
|
|||||||
graph.get(2).add(1);
|
graph.get(2).add(1);
|
||||||
graph.get(0).add(2);
|
graph.get(0).add(2);
|
||||||
|
|
||||||
//Printing all the edges
|
vertexCount = graph.size();
|
||||||
for(int vertexNo=0; vertexNo<numVertices; vertexNo++) {
|
for(int i = 0; i < vertexCount; i++) {
|
||||||
int edgeCount = graph.get(vertexNo).size();
|
int edgeCount = graph.get(i).size();
|
||||||
ArrayList<Integer> listOfVertices = graph.get(vertexNo);
|
for(int j = 0; j < edgeCount; j++) {
|
||||||
for(int i=0; i<edgeCount; i++) {
|
Integer startVertex = i;
|
||||||
System.out.println("Vertex "+vertexNo+" is connected to vetex "+listOfVertices.get(i));
|
Integer endVertex = graph.get(i).get(j);
|
||||||
|
System.out.printf("Vertex %d is connected to vertex %d%n", startVertex, endVertex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ public class ThreeDimensionalArrayList {
|
|||||||
ArrayList< ArrayList< ArrayList<String> > > space = new ArrayList<>(x_axis_length);
|
ArrayList< ArrayList< ArrayList<String> > > space = new ArrayList<>(x_axis_length);
|
||||||
|
|
||||||
//Initializing each element of ArrayList with ArrayList< ArrayList<String> >
|
//Initializing each element of ArrayList with ArrayList< ArrayList<String> >
|
||||||
for(int i=0; i< x_axis_length; i++) {
|
for(int i = 0; i < x_axis_length; i++) {
|
||||||
space.add(new ArrayList< ArrayList<String> >(y_axis_length));
|
space.add(new ArrayList< ArrayList<String> >(y_axis_length));
|
||||||
for(int j =0; j< y_axis_length; j++) {
|
for(int j = 0; j < y_axis_length; j++) {
|
||||||
space.get(i).add(new ArrayList<String>(z_axis_length));
|
space.get(i).add(new ArrayList<String>(z_axis_length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,9 +33,9 @@ public class ThreeDimensionalArrayList {
|
|||||||
space.get(1).get(1).add(1,"Yellow");
|
space.get(1).get(1).add(1,"Yellow");
|
||||||
|
|
||||||
//Printing colors for all the points
|
//Printing colors for all the points
|
||||||
for(int i=0; i<x_axis_length; i++) {
|
for(int i = 0; i < x_axis_length; i++) {
|
||||||
for(int j=0; j<y_axis_length; j++) {
|
for(int j = 0; j < y_axis_length; j++) {
|
||||||
for(int k=0; k<z_axis_length; k++) {
|
for(int k = 0; k < z_axis_length; k++) {
|
||||||
System.out.println("Color of point ("+i+","+j+","+k+") is :"+space.get(i).get(j).get(k));
|
System.out.println("Color of point ("+i+","+j+","+k+") is :"+space.get(i).get(j).get(k));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user