* Making examples simple

* Changing variable names
This commit is contained in:
rahusriv 2018-12-30 08:40:43 +05:30 committed by KevinGilmore
parent 99774f8730
commit 676f55e872
2 changed files with 20 additions and 22 deletions

View File

@ -6,30 +6,28 @@ public class ArrayListOfArrayList {
public static void main(String args[]) {
int vertex = 5;
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(vertex);
int numVertices = 3;
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(numVertices);
//Initializing each element of ArrayList with ArrayList
for(int i=0; i< vertex; i++) {
for(int i=0; i< numVertices; i++) {
graph.add(new ArrayList<Integer>());
}
//We can add any number of columns to each row
graph.get(0).add(1);
graph.get(0).add(5);
graph.get(1).add(0);
graph.get(1).add(2);
graph.get(2).add(0);
graph.get(1).add(0);
graph.get(2).add(1);
graph.get(2).add(3);
graph.get(3).add(2);
graph.get(3).add(4);
graph.get(4).add(3);
graph.get(4).add(5);
graph.get(0).add(2);
//Printing all the edges
for(int i=0; i<vertex; i++) {
for(int j=0; j<graph.get(i).size(); j++) {
System.out.println("Edge between vertex "+i+"and "+graph.get(i).get(j));
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));
}
}
}

View File

@ -20,17 +20,17 @@ public class ThreeDimensionalArrayList {
}
//Set Red color for points (0,0,0) and (0,0,1)
space.get(0).get(0).add("Red");
space.get(0).get(0).add("Red");
space.get(0).get(0).add(0,"Red");
space.get(0).get(0).add(1,"Red");
//Set Blue color for points (0,1,0) and (0,1,1)
space.get(0).get(1).add("Blue");
space.get(0).get(1).add("Blue");
space.get(0).get(1).add(0,"Blue");
space.get(0).get(1).add(1,"Blue");
//Set Green color for points (1,0,0) and (1,0,1)
space.get(1).get(0).add("Green");
space.get(1).get(0).add("Green");
space.get(1).get(0).add(0,"Green");
space.get(1).get(0).add(1,"Green");
//Set Yellow color for points (1,1,0) and (1,1,1)
space.get(1).get(1).add("Yellow");
space.get(1).get(1).add("Yellow");
space.get(1).get(1).add(0,"Yellow");
space.get(1).get(1).add(1,"Yellow");
//Printing colors for all the points
for(int i=0; i<x_axis_length; i++) {