经典的货郎担问题解决办法

源代码在线查看: markarray.java

软件大小: 1405 K
上传用户: kens
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

								/*				** This code was written by Kent Paul Dolan.  See accompanying file				** TravellerDoc.html for status for your use.				*/								package com.well.www.user.xanthian.java.tools;								public class MarkArray				{				  private boolean m_marks[] = null;				  private int     m_setCount = 0;								  public MarkArray( int size ) 				  {				    m_marks = new boolean[ size ];				    for ( int i=0; i				    m_setCount = 0;				  }								  public synchronized void setAllMarksTrue()				  {				    for ( int i=0; i				    m_setCount = m_marks.length;				  }								  public synchronized void setAllMarksFalse()				  {				    for ( int i=0; i				    m_setCount = 0;				  }								  public synchronized boolean setMarkAndCheckIfAllMarksAreSet( int index )				  {				    if ( m_marks[ index ] == false )				    {				      m_setCount++;				      m_marks[ index ] = true;				    }								    if ( m_setCount == m_marks.length )				    {				      return true;				    }				    else				    {				      return false;				    }				  }								  public synchronized boolean clearMarkAndCheckIfAllMarksAreClear( int index )				  {				    if ( m_marks[ index ] == true )				    {				      m_setCount--;				      m_marks[ index ] = false;				    }								    if ( m_setCount == 0 )				    {				      return true;				    }				    else				    {				      return false;				    }				  }								  public synchronized void clear( int index )				  {				    m_marks[ index ] = false;				  }								  public synchronized void set( int index )				  {				    m_marks[ index ] = true;				  }								  public synchronized int getCount()				  {				    return m_setCount;				  }								}							

相关资源