Repository navigation
Expand file tree
/
Copy pathsample.cpp
More file actions
73 lines (69 loc) · 2 KB
/
Copy pathsample.cpp
File metadata and controls
73 lines (69 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "GS_Func_Stack.h"
#include "sample.h"
void StackSample::Conversion()
{
GSStackFunc<int> stackFunc;
GSStackFunc<int>::SqStack S;
int N = 0;
int e = 0;
stackFunc.InitStack(S);
printf( "Please Enter A NUM: " );
scanf( "%d", &N);//Attention: %d without /n
while( N )
{
if( ! stackFunc.Push( S, N%8 ))
{
printf( "Push Wrong!" );
}
N = N/8;
}
printf( "10 to 8 result: ");
while( !stackFunc.StackEmpty( S ))
{
if( ! stackFunc.Pop( S, e ))
{
printf( "Pop Wrong!" );
}
printf( "%d", e );
}
printf( "\n" );
stackFunc.DestroyStack( S );
}//conversion
void StackSample::LineEdit()
{
GSStackFunc<char> stackFunc;
GSStackFunc<char>::SqStack S;
char c;
stackFunc.InitStack( S );
char ch = getchar();
while ( ch != EOF )
{
while ( ch != EOF && ch != '\n' )
{
switch( ch )
{
case '#':
stackFunc.Pop( S, c );
break;
case '@':
stackFunc.ClearStack( S );
break;
default:
stackFunc.Push( S, ch );
break;
}
ch = getchar();
}
while ( stackFunc.Pop( S, c ))
{
printf( "%c", c);
}
//printf( "%s", S.base );
stackFunc.ClearStack( S );
if ( ch != EOF )
{
ch = getchar();
}
}
stackFunc.DestroyStack( S );
}