.


:




:

































 

 

 

 


Stack .




// Stack, using System;

// , class Stack {

// , char[] stck; // , int tos; //

// Stack , public Stack(int size) {

stck = new char[size]; // tos = 0;

}

// , public void Push(char ch) { if(tos==stck.Length) {

Console.WriteLine (" - ."); return;

}

stck[tos] = ch; tos++;

}

// , public char Pop() {

if(tos==0) {

Console.WriteLine(" - ."); return (char) 0;

}

Tos ;

return stck[tos];

}

// true, , public bool IsFullO { return tos==stck.Length;

}

// true, - , public bool IsEmptyO {

return tos==0;

}

// , public int Capacity() {

Return stck.Length;

}

// , , public int GetNum() { return tos;

}

}

class StackDemo {

static void Main() {

Stack stkl = new Stack (10);

Stack stk2 = new Stack(lO);

Stack stk3 = new Stack(10);

Char ch; int i;

// stkl.

Console.WriteLine(" -J stkl."); for(i=0;!stkl.IsFull(); i++) stkl.Push((char) ('A1 + i));

if(stkl.IsFull()) Console.WriteLine(" stkl .");

// stkl.

Console.Write(" stkl: "); while(!stkl.IsEmpty()) {

ch = stkl.Pop();

Console.Write(ch);

}

Console.WriteLine();

if(stkl.IsEmpty()) Console.WriteLine(" stkl .\");

// stkl.

Console.WriteLine(" -J stkl."); for(i=0;!stkl.IsFull(); i++) stkl.Push((char) ('A' + i));

// stkl stk2. // stk2 . Console.WriteLine(" stkl\n" +

" stk2."); while(!stkl.IsEmpty()) {

ch = stkl.Pop(); stk2.Push(ch);

Console.Write(" stk2: "); while(!stk2.IsEmpty()) {

ch = stk2.Pop();

Console.Write(ch);

}

Console.WriteLine("\n");

// 5 .

Console.WriteLine(" 5 stk3."); for(i=0; i < 5; i++)

stk3.Push((char) ('A1 + i));

Console.WriteLine(" stk3: " + stk3.Capacity()); Console.WriteLine(" stk3: " + stk3.GetNum());

}

}

.

-J stkl.

stkl .

stkl: JIHGFEDCBA stkl .

-J stkl.

stkl stk2.

stk2: ABCDEFGHIJ

5 stk3.

stk3: 10 stk3: 5

, , , int double. , , . . .

// .

Using System;

class MyClass { int alpha, beta;

public MyClass(int i, int j) { alpha = i; beta = j;

// true, ob // , , public bool SameAs(MyClass ob) {

if ((ob.alpha == alpha) & (ob.beta == beta)) return true; else return false;

}

// ob. public void Copy(MyClass ob) { alpha = ob.alpha; beta = ob.beta;

}

public void Show() {

Console.WriteLine("alpha: {0}, beta: {1}", alpha, beta);

}

}

class PassOb {

static void Main() {

MyClass obi = new MyClass(4, 5);

MyClass ob2 = new MyClass (6, 7);

Console.Write("obi: "); obi.Show ();

Console.Write("ob2: "); ob2.Show();

If(obi.SameAs(ob2))

Console.WriteLine("obi ob2 ."); else

Console.WriteLine("obi ob2 ."); Console.WriteLine();

// obi ob2. obi.Copy(ob2);

Console.Write("obi : "); obi.Show();

If(obi.SameAs(ob2))

Console.WriteLine("obi ob2 ."); else

Console.WriteLine("obi ob2 .");

}

}





:


: 2016-12-03; !; : 391 |


:

:

, .
==> ...

1488 - | 1399 -


© 2015-2024 lektsii.org - -

: 0.013 .