Skip to content

Commit 4cd323c

Browse files
authored
Add files via upload
1 parent b98cdcc commit 4cd323c

9 files changed

+867
-0
lines changed
658 Bytes
Binary file not shown.

the_metro_app/Graph_M$Pair.class

370 Bytes
Binary file not shown.

the_metro_app/Graph_M$Vertex.class

453 Bytes
Binary file not shown.

the_metro_app/Graph_M.class

13.7 KB
Binary file not shown.

the_metro_app/Graph_M.java

Lines changed: 704 additions & 0 deletions
Large diffs are not rendered by default.

the_metro_app/Heap.class

2.4 KB
Binary file not shown.

the_metro_app/Heap.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import java.util.ArrayList;
2+
import java.util.HashMap;
3+
4+
public class Heap<T extends Comparable<T>>
5+
{
6+
ArrayList<T> data = new ArrayList<>();
7+
HashMap<T, Integer> map = new HashMap<>();
8+
9+
public void add(T item)
10+
{
11+
data.add(item);
12+
map.put(item, this.data.size() - 1);
13+
upheapify(data.size() - 1);
14+
}
15+
16+
private void upheapify(int ci)
17+
{
18+
int pi = (ci - 1) / 2;
19+
if (isLarger(data.get(ci), data.get(pi)) > 0)
20+
{
21+
swap(pi, ci);
22+
upheapify(pi);
23+
}
24+
}
25+
26+
private void swap(int i, int j)
27+
{
28+
T ith = data.get(i);
29+
T jth = data.get(j);
30+
31+
data.set(i, jth);
32+
data.set(j, ith);
33+
map.put(ith, j);
34+
map.put(jth, i);
35+
}
36+
37+
public void display()
38+
{
39+
System.out.println(data);
40+
}
41+
42+
public int size()
43+
{
44+
return this.data.size();
45+
}
46+
47+
public boolean isEmpty()
48+
{
49+
return this.size() == 0;
50+
}
51+
52+
public T remove()
53+
{
54+
swap(0, this.data.size() - 1);
55+
T rv = this.data.remove(this.data.size() - 1);
56+
downheapify(0);
57+
58+
map.remove(rv);
59+
return rv;
60+
}
61+
62+
private void downheapify(int pi)
63+
{
64+
int lci = 2 * pi + 1;
65+
int rci = 2 * pi + 2;
66+
int mini = pi;
67+
68+
if (lci < this.data.size() && isLarger(data.get(lci), data.get(mini)) > 0)
69+
{
70+
mini = lci;
71+
}
72+
73+
if (rci < this.data.size() && isLarger(data.get(rci), data.get(mini)) > 0)
74+
{
75+
mini = rci;
76+
}
77+
78+
if (mini != pi)
79+
{
80+
swap(mini, pi);
81+
downheapify(mini);
82+
}
83+
}
84+
85+
public T get()
86+
{
87+
return this.data.get(0);
88+
}
89+
90+
public int isLarger(T t, T o)
91+
{
92+
return t.compareTo(o);
93+
}
94+
95+
public void updatePriority(T pair)
96+
{
97+
int index = map.get(pair);
98+
upheapify(index);
99+
}
100+
}

the_metro_app/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# DELHI METRO RAIL APP
2+
3+
Please don't get confused, this is NOT an ANDROID Application!
4+
5+
This is a simple Java program that will take information (name) of the source station and the destination station, of Delhi Metro, from the user and display the fare and shortest metro route to reach the destination. It will also be having a metro map for commuter’s better navigation.
6+
7+
The idea is implemented using Graph and Heap data structures.
8+
The graph has nodes and edges. Nodes represent a metro station that will be containing certain information regarding that station like its name, its metro corridor, and the lines which it connects. Edges (the connection between two nodes) represent the distance between the two stations and the cost of each edge will be equal to the distance between the two of its connecting stations(nodes).
9+
10+
By using different algorithms like Dijkstra, breadth-first search, depth-first search, etc, the shortest path between the source station and the destination station is determined, and accordingly, the fare is being calculated on the basis of the total distance between the two stations. Finally, the metro route between the two stations and the total fare is displayed.
11+
12+
Main.java cointains all the major code and Heap.java contains heap implementation.
13+
14+
15+
## REQUIREMENTS
16+
17+
> The project can run on any online or offline Integrated Development Environment (IDE) like Eclipse, Netbeans, ideone.com, etc.
18+
> You should have at least elementary knowledge of Java Programming language to work on the project.
19+
> Knowledge of data structures like Graph and Heap and Algorithms like Dijkstra, BFS, DFS, etc is appreciated, however, it is not essential.
20+
> And lastly, some understanding of the Collection framework makes it a cakewalk journey. (If you don't know about the Collection framework it is not a problem, you can proceed without it and while working if you feel the need to know you can refer to https://www.geeksforgeeks.org/collections-in-java-2/ ).
21+
22+
23+
## That was all... You are all set to work on the project!!!!
24+

the_metro_app/Requirements.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Requirements
2+
3+
## Java Collection framework
4+
5+
The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.
6+
7+
![flowchart](https://user-images.githubusercontent.com/71463658/101475597-9db6f400-3972-11eb-8b9f-dec58a00104f.png)
8+
9+
## Collection framework used in this project
10+
11+
### In Graph_M.java
12+
13+
* ArrayList
14+
* LinkedList
15+
* Stack
16+
* HashMap
17+
18+
### In Heap.java
19+
20+
* HashMap
21+
* ArrayList
22+
23+
24+
25+
## Data Structures
26+
Data structure is a way of organizing data in the computer so that it can be used effectively.
27+
The data structures used in this project are:
28+
* Array
29+
* HashMap
30+
* Linked List
31+
* Heap
32+
* Stack
33+
* Graph
34+
35+
* The array data structure is implemented using ArrayList class which is a resizable array.It stores data in contiguous memory locations.
36+
* Hashmap data structure is used to store key-value pairs.
37+
* The stack data structure required by the algorithm is implemented using linked list.It follows the principle Last In First Out(LIFO)
38+
* Heap is implemented with the help of ArrayList and HashMap.It is a tree based data structure where all elements of the tree are in a particular order.
39+
* Graph is a complex data structure containing vertices and edges connecting these vertices.This is implemented in the project with the help of ArrayList and HashMap.

0 commit comments

Comments
 (0)