Mazdak Farrokhzad edited Appendix.tex  over 10 years ago

Commit id: da714b5458dab24cff9888a39da6c74b4f7da069

deletions | additions      

       

\section{Appendix}  \usepackage{color}  \usepackage{listings}  \lstset{ %  language=C++, language=Java,  % choose the language of the code basicstyle=\footnotesize, % the size of the fonts that are used for the code  numbers=left, % where to put the line-numbers  numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers 

showstringspaces=false, % underline spaces within strings  showtabs=false, % show tabs within strings adding particular underscores  frame=single, % adds a frame around the code  tabsize=2, tabsize=4,  % sets default tabsize to 2 spaces captionpos=b, % sets the caption-position to bottom  breaklines=true, % sets automatic line breaking  breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace 

}  \begin{lstlisting}  !!code!! import java.util.Random;     public final class MaxSum {   // globala, lagrar start och slut pÃ¥ sekvensen   public static int seqStart = 0;   public static int seqEnd = -1;     /**   * contiguous subsequence sum algorithm.   * seqStart and seqEnd represent the actual best sequence.   * Version 1   */   public static int maxSubSum1( int[] a ) {   int maxSum = 0;   for( int i = 0; i < a.length; i++ )   for( int j = i; j < a.length; j++ ) {   int thisSum = 0;   for( int k = i; k <= j; k++ ) {   thisSum += a[k];   }   if( thisSum > maxSum ) {   maxSum = thisSum;   seqStart = i;   seqEnd = j;   }   }   return maxSum;   }     // Version 2   public static int maxSubSum2( int [ ] a ) {   int maxSum = 0;   for( int i = 0; i < a.length; i++ ) {   int thisSum = 0;   for( int j = i; j < a.length; j++ ) {   thisSum += a[ j ];   if( thisSum > maxSum ) {   maxSum = thisSum;   seqStart = i;   seqEnd = j;   }   }   }   return maxSum;   }     // Version 3   public static int maxSubSum3( int[] a ) {   int maxSum = 0;   int thisSum = 0;   for( int i = 0, j = 0; j < a.length; j++ ) {   thisSum += a[ j ];   if( thisSum > maxSum ) {   maxSum = thisSum;   seqStart = i;   seqEnd = j;   }   else if( thisSum < 0 ) {   i = j + 1;   thisSum = 0;   }   }   return maxSum;   }   }  \end{lstlisting}