C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 20th, 2004, 12:53 AM
calabisix calabisix is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 calabisix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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





Reply With Quote
  #2  
Old November 21st, 2004, 11:36 PM
calabisix calabisix is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 calabisix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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??

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Playing with the Stack...question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway