Skip to main content

Driver program to perform operations in graph

Driver program to perform operations in graph:-



package com.problems.graph;

public class GraphDriver {

 public static void main(String[] args)
 {
  BFSGraph g=new BFSGraph();
  g.addVertex('A');
  g.addVertex('B');
  g.addVertex('C');
  g.addVertex('D');
  g.addVertex('E');
  g.addVertex('F');
  g.addVertex('G');
  g.addVertex('H');
 
  g.addEdge(0, 1);
  g.addEdge(1, 2);
  g.addEdge(1, 7);
  g.addEdge(2, 3);
  g.addEdge(2, 4);
  g.addEdge(7, 4);
  g.addEdge(4, 5);
  g.addEdge(4, 6);
  g.bfs();
 }
 
}

Comments

.

Popular posts from this blog

5 books that your college doesn’t tell to read seriously for PLACEMENTS

1.               Let us C - It can be the best book to pick in your first semester itself. The book is written in a very simple style so you can easily grasp most of the concepts of programming by just working hard on it. It will help you in building basics of programming around c language. 2.               HEAD FIRST JAVA- This book you should buy in third semester and invest your whole second year into it by working on all the codes. This book will help you teaching the concepts in a very attractive way. You will never bore while working  through this book. 3.               Data Structure Made Easy In Java - As soon you finished studying core java in the 4 th semester just pick this book to understand the logic’s of data structure and algorithms. It will help you to go deep inside this subject from which questions are frequently asked in all the interviews. This book carries a great set of problems that will help in developing intellectual knowledge around

Finding a loop in a linked List

Finding a loop in a linked List:- public class LinkedListLoop { //Two pointers public Node loopCheck ( Node head ) { //fast pointer take two steps at a time Node fastptr = head ; //slow pointer take one step at a time Node slowptr = head ; if ( head == null ) { System . out . println ( "no loops empty list" ); } //Till any pointer becomes null while ( slowptr != null && fastptr != null && fastptr . next != null ) { slowptr = slowptr . next ; fastptr = fastptr . next . next ; //if both pointers point to same node //possible only in loop list if ( slowptr == fastptr ) { System . out . println ( "loopfound" ); fastptr = head ; while ( fastptr . next != slowptr ) { fastptr = fastptr . next ; } return fastptr ; } } System . out . println ( "loop not found" ); return head ; } public void makeCycle ( N