LAPORAN ALGORITMA DAN STRUKTUR DATA II (5)

LAPORAN PRAKTIKUM
ALGORITMA DAN STRUKTUR DATA II
MODUL
GRAPH

Disusun Oleh :
Syukur Jaya Mendrofa
201501072
Kelas: C

Dosen Pengampu :
Oskar Ika Adi Nugroho, ST., MT

JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER “YOS SUDARSO”
PURWOKERTO
2016

BAB I
DASAR TEORI


Graf (graph) adalah sebuah konsep struktur data yang terdiri dari kumpulan simpul (node)
dan garis (edge). Sebuah garis harus diawali dan diakhiri dengan sebuah simpul.
Suatu Graph mengandung 2 himpunan,yaitu:
1. Himpunan V yang elemennya disebut simpul (Vertex atau Point atau Node atau
Titik).
2. Himpunan E yang merupakan pasangan tak urut dari simpul. Anggotanya disebut
Ruas (Edge atau rusuk atau sisi).
Contoh :
Graph berikut menyatakan Graph G (E,V) dengan :
1. V mengandung 4 simpul, yaitu A, B, C, D.
2. E mengandung 5 ruas, yaitu :
1. e1 = (A, B)
2. e2 = (B, C)
3. e3 = (A, D)
4. e4 = (D, C)
5. e5 = (B, D)

Jenis-jenis Graph :






Graph berarah tidak berbobot.
Graph berarah berbobot.
Graph tidak berarah tidak berbobot.
Graph tidak berarah berbobot.

BAB II
TUGAS
#include
#include
#include
using namespace std;
class Vertex;
class Edge
{
public:
Edge (Vertex *org, Vertex *dest, int dist)
{

origin = org;
destination = dest;
distance = dist;
}
Vertex* getOrigin() {return origin;}
Vertex* getDestination() {return destination;}
int getDistance() {return distance;}
private:
Vertex* origin;
Vertex* destination;
int distance;
};
class Vertex
{
public:
Vertex(string id)
{
name = id;
}
void addEdge(Vertex *v, int dist)

{
Edge newEdge(this, v, dist);
edges.push_back(newEdge);
}
void printEdges()

{
cout