Generate random stack operation sequences

xiaoxiao2021-03-05  25

Public String Getopstring (int C)

{

StringBuffer SB = new stringbuffer ();

Random rnd = new random ();

INT PN, QN;

Pn = Qn = 0;

Char M;

Final char [] mm = new char [] {'p', 'q'};

While ((Qn PN) <(2 * c))

{m = mm [rnd.nextint (2)];

IF (m == 'p')

Pn ;

Else

Qn ;

IF (PN> C)

{Sb.append ('q');

PN -;

Qn ;

}

ELSE IF (pn == c)

sb.append (m);

Else

{

IF (qn> = c)

{

Sb.append ('p');

Qn--

Pn ;

} // if

Else

{IF (Qn> PN)

{sb.append ('p');

Qn--

Pn ;}

Else

sb.append (m);

} // else

} // else

} // while

String op = sb.toString ();

Return OP;

}

转载请注明原文地址:https://www.9cbs.com/read-37799.html

New Post(0)