adsa lab(me cse)

Post on 20-Sep-2015

268 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

ADSA LAB(ME CSE)

TRANSCRIPT

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

top related