| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Playing with the Stack...question
Hi
I was playing around with a stack example from MSDN using push and pop. Here is the MSDN Code: [C++] #using <mscorlib.dll> #using <system.dll> using namespace System; using namespace System::Collections; void PrintValues( IEnumerable* myCollection, char mySeparator ) { System::Collections::IEnumerator* myEnumerator = myCollection->GetEnumerator(); while ( myEnumerator->MoveNext() ) Console::Write( S"{0}{1}", __box(mySeparator), myEnumerator->Current ); Console::WriteLine(); } void main() { // Creates and initializes a new Stack. Stack* myStack = new Stack(); myStack->Push( S"The" ); myStack->Push( S"quick" ); myStack->Push( S"brown" ); myStack->Push( S"fox" ); // Displays the Stack. Console::Write( S"Stack values:" ); PrintValues( myStack, '\t' ); // Removes an element from the Stack. Console::WriteLine( S"(Pop)\t\t{0}", myStack->Pop() ); // Displays the Stack. Console::Write( S"Stack values:" ); PrintValues( myStack, '\t' ); // Removes another element from the Stack. Console::WriteLine( S"(Pop)\t\t{0}", myStack->Pop() ); // Displays the Stack. Console::Write( S"Stack values:" ); PrintValues( myStack, '\t' ); // Views the first element in the Stack but does not remove it. Console::WriteLine( S"(Peek)\t\t{0}", myStack->Peek() ); // Displays the Stack. Console::Write( S"Stack values:" ); PrintValues( myStack, '\t' ); } /* This code produces the following output. Stack values: fox brown quick The (Pop) fox Stack values: brown quick The (Pop) brown Stack values: quick The (Peek) quick Stack values: quick The */ When I run my program (from what I can see it is exact as the MSDN example) my output creates 9's! Stack values: 9fox9brown9quick9The (Pop) fox Stack values:9brown9quick9The (Pop) brown Stack values:9quick9The (Peek) quick Stack values: 9quick9The I suspect it has something to do with the mySeperator parameter in the PrintValue function but not sure. Just curious on what is going on here! Thanks |
|
#2
|
|||
|
|||
|
HI
I am curious...is this a difficult problem and no one knows the answer...or is this to simple and I should know the answer?? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Playing with the Stack...question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|