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[]) {
|
||||
|
||||
int numVertices = 3;
|
||||
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(numVertices);
|
||||
int vertexCount = 3;
|
||||
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(vertexCount);
|
||||
|
||||
//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>());
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,14 @@ public class ArrayListOfArrayList {
|
|||
graph.get(1).add(0);
|
||||
graph.get(2).add(1);
|
||||
graph.get(0).add(2);
|
||||
|
||||
//Printing all the edges
|
||||
for(int vertexNo=0; vertexNo<numVertices; vertexNo++) {
|
||||
int edgeCount = graph.get(vertexNo).size();
|
||||
ArrayList<Integer> listOfVertices = graph.get(vertexNo);
|
||||
for(int i=0; i<edgeCount; i++) {
|
||||
System.out.println("Vertex "+vertexNo+" is connected to vetex "+listOfVertices.get(i));
|
||||
|
||||
vertexCount = graph.size();
|
||||
for(int i = 0; i < vertexCount; i++) {
|
||||
int edgeCount = graph.get(i).size();
|
||||
for(int j = 0; j < edgeCount; j++) {
|
||||
Integer startVertex = 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);
|
||||
|
||||
//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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public class ThreeDimensionalArrayList {
|
|||
space.get(1).get(1).add(1,"Yellow");
|
||||
|
||||
//Printing colors for all the points
|
||||
for(int i=0; i<x_axis_length; i++) {
|
||||
for(int j=0; j<y_axis_length; j++) {
|
||||
for(int k=0; k<z_axis_length; k++) {
|
||||
for(int i = 0; i < x_axis_length; i++) {
|
||||
for(int j = 0; j < y_axis_length; j++) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue