NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//name: date:
//for use with EdgeList, DFS-BFS, and EdgeListCities

import java.io.*;
import java.util.*;

class Vertex implements VertexInterface
{
private final String name;
private ArrayList<Vertex> adjacencies;

public Vertex(String n)
{
name = n;
adjacencies = new ArrayList();
}

public String getName()
{
return name;
}

public ArrayList<Vertex> getAdjacencies()
{
return adjacencies;
}
/* enter your code here */
}

public class TJGraphAdjList_5G_Dhanasekar
{
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
private Map<String, Integer> nameToIndex = new HashMap<String, Integer>();

public void addVertex(String n)
{
boolean contains = false;
for(int x = 0; x < vertices.size(); x++)
{
if(vertices.get(x).getName().equals(n))
{
contains = true;
}
}
if(!contains)
{
vertices.add(new Vertex(n));
nameToIndex.put(n, vertices.size() - 1);
}

}

public void addEdge(String n, String n1)
{
int index = nameToIndex.get(n);
Vertex temp = vertices.get(index);
temp.getAdjacencies().add(new Vertex(n1));
}

public String toString()
{
String y = "";
for(int x = 0; x < vertices.size(); x++)
{
y += vertices.get(x).getName() + " [ ";
for(int z = 0; z < vertices.get(x).getAdjacencies().size(); z++)
{
y += vertices.get(x).getAdjacencies().get(z).getName() + " ";
}
y += "]n";
}
return y;
}

public Map<String, Integer> getVertexMap()
{
return nameToIndex;
}

public List<Vertex> depthFirstSearch(String name)
{
ArrayList<Vertex> tempL = new ArrayList<Vertex>();
Stack<Vertex> tempS = new Stack<Vertex>();


while(tempS.size() != 0)
{
tempS.push(new Vertex(name));
tempL.add(tempS.pop());
ArrayList<Vertex> temp = vertices.get(nameToIndex.get(name)).getAdjacencies();
for(int x = 0; x < temp.size(); x++)
{
Vertex n1 = temp.get(x);
boolean contains = false;
if(tempL.contains(n1))
{
contains = true;
}
if(!contains)
{
tempS.push(n1);
}
}
name = tempS.pop().getName();
}
return tempL;

}

public List<Vertex> breadthFirstSearch(String name)
{
ArrayList<Vertex> tempL = new ArrayList<Vertex>();
Queue<Vertex> tempS = new Queue<Vertex>();


while(tempS.size() != 0)
{
tempS.add(new Vertex(name));
tempL.add(tempS.remove());
ArrayList<Vertex> temp = vertices.get(nameToIndex.get(name)).getAdjacencies();
for(int x = 0; x < temp.size(); x++)
{
Vertex n1 = temp.get(x);
boolean contains = false;
if(tempL.contains(n1))
{
contains = true;
}
if(!contains)
{
tempS.push(n1);
}
}
name = tempS.pop().getName();
}
return tempL;
}

}
interface VertexInterface
{
public String toString(); //just return the name
public String getName();
public ArrayList<Vertex> getAdjacencies();
}

interface TJGraphAdjListInterface
{
/********************* Graphs 3: EdgeList *******************************/
public List<Vertex> getVertices();
public Vertex getVertex(int i) ;

public Vertex getVertex(String vertexName);
public Map<String, Integer> getVertexMap();
public void addVertex(String v);
public void addEdge(String source, String target);
public String toString();




/*********************Graphs 4: DFS and BFS ****************************/
//public List<Vertex> depthFirstSearch(String name);
// public List<Vertex> breadthFirstSearch(String name);
// public List<Vertex> depthFirstRecur(String name);



/****************Graphs 5: EdgeList with Cities *********/
// public void graphFromEdgeListData(String fileName) throws FileNotFoundException;
// public int edgeCount();
// public boolean isReachable(String source, String target);
// public boolean isConnected();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.