ADSA LAB(ME CSE)

118
EX.NO.1(A). BREADTH FIRST SEARCH AIM:TO Implement the breadh firt search algoriyhm in the grph traverse. ALGORITHM: 1.Start the program 2.Precondition will display the array of vertices 3.Post condition will display the DFS in the graph Vertex public vertex(char lab) { Label=lab; Wasvisited=false; } 4.vertex which connecting the code of vertex { For(int j=0;i<vertex;j++) If(adjmat[v][j]==1&& vertexlist [j] wasvisited==false) Return j; Return -1; } 5.find the overall vertex in the graph. 6.stop the program.

description

ADSA LAB(ME CSE)

Transcript of ADSA LAB(ME CSE)

EX.NO.1(A). BREADTH FIRST SEARCH

AIM:TO Implement the breadh firt search algoriyhm in the grph traverse.ALGORITHM:

1.Start the program

2.Precondition will display the array of vertices

3.Post condition will display the DFS in the graph

Vertex public vertex(char lab)

{

Label=lab;

Wasvisited=false;

}

4.vertex which connecting the code of vertex

{

For(int j=0;i for (int i = 0; i < 300; i++)

To increment the counter value by using getAndIncrement()

Exit the program, while condition is exist.

source code:

import java.util.concurrent.*;

public class Exercise { static int counter = 0;

static synchronized int getAndIncrement() { return counter++; }

static class Improper implements Runnable {

@Override public void run() { for (int i = 0; i < 300; i++) { getAndIncrement(); } } }

public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(3); for (int i = 0; i < 300; i++) { executorService.submit(new Improper()); } executorService.shutdown(); System.out.println(counter); }}

OUTPUT: result:

For a given input, the program successfully executed concurrent stack