Click here to Skip to main content
15,890,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionfind folder list on a root folder Pin
Game-point20-Jan-10 1:59
Game-point20-Jan-10 1:59 
QuestionRe: find folder list on a root folder Pin
David Crow20-Jan-10 2:50
David Crow20-Jan-10 2:50 
AnswerRe: find folder list on a root folder Pin
Richard MacCutchan20-Jan-10 2:50
mveRichard MacCutchan20-Jan-10 2:50 
AnswerRe: find folder list on a root folder Pin
Graham Breach20-Jan-10 2:54
Graham Breach20-Jan-10 2:54 
QuestionWhat is Data Directory in PE file format ? Why? Pin
glitteringsound20-Jan-10 0:52
glitteringsound20-Jan-10 0:52 
QuestionRe: What is Data Directory in PE file format ? Why? Pin
David Crow20-Jan-10 2:51
David Crow20-Jan-10 2:51 
AnswerRe: What is Data Directory in PE file format ? Why? Pin
Richard MacCutchan20-Jan-10 2:53
mveRichard MacCutchan20-Jan-10 2:53 
Questionproblem with stack structure in C++(using pointer), plz help !!! Pin
hung2h19-Jan-10 23:00
hung2h19-Jan-10 23:00 
#include <iostream>
using namespace std;

class Element{

public:
	int value;
	Element *next;

	Element() : value(0), next(NULL) {}
	Element(int v) : value(v), next(NULL) {}
	Element(int v,Element *n) : value(v), next(n) {}
};

class Stack{

private:
	int length;
	Element head;

public:
	Stack() : head(), length(0) {}

	void clear();
	void traversal() const;
	void push(int value);
	int pop();
};


void Stack::clear(){
	head = Element();
}

void Stack::traversal() const{
	if (length == 0)
		cout << "The stack is empty" << endl;
	else{
		Element e = head;
		while(true){
			cout << e.value << ' ';
			if (e.next != NULL)
				e = *e.next;
			else
				break;
		}
	}
}
void Stack::push(int value){
	if (length == 0)
		head = Element(value);
	else
		head = Element(value,&head);

	length++;
}

int Stack::pop(){
	return 0;
}




int main(int argc, string args[]){
	Stack s;
	
	cout << endl;

	for (int i = 0; i < 10; i++)
		s.push(i);
	s.traversal();

	cout << endl;

	return 0;
}

well, i m trying to implement stack structure with C++. i got a problem with this code. the traversal function runs forever, and it prints out all '9'. can any1 help with this problem ?
AnswerRe: problem with stack structure in C++(using pointer), plz help !!! Pin
Cedric Moonen19-Jan-10 23:28
Cedric Moonen19-Jan-10 23:28 
GeneralRe: problem with stack structure in C++(using pointer), plz help !!! Pin
hung2h19-Jan-10 23:43
hung2h19-Jan-10 23:43 
AnswerRe: problem with stack structure in C++(using pointer), plz help !!! Pin
CPallini19-Jan-10 23:44
mveCPallini19-Jan-10 23:44 
GeneralRe: problem with stack structure in C++(using pointer), plz help !!! Pin
Tim Craig20-Jan-10 12:55
Tim Craig20-Jan-10 12:55 
GeneralRe: problem with stack structure in C++(using pointer), plz help !!! Pin
CPallini20-Jan-10 21:32
mveCPallini20-Jan-10 21:32 
QuestionMessage Removed Pin
19-Jan-10 22:40
Mishgun5619-Jan-10 22:40 
AnswerRe: The problem with including headers in C++ Pin
Stuart Dootson19-Jan-10 22:48
professionalStuart Dootson19-Jan-10 22:48 
AnswerRe: The problem with including headers in C++ Pin
Stephen Hewitt19-Jan-10 22:50
Stephen Hewitt19-Jan-10 22:50 
GeneralRe: The problem with including headers in C++ Pin
Mishgun5619-Jan-10 22:56
Mishgun5619-Jan-10 22:56 
QuestionSwitching on and setting baud rate [modified] Pin
CodeyBlank19-Jan-10 21:28
CodeyBlank19-Jan-10 21:28 
AnswerRe: Switching on and setting baud rate Pin
Richard MacCutchan19-Jan-10 22:27
mveRichard MacCutchan19-Jan-10 22:27 
GeneralRe: Switching on and setting baud rate Pin
Garth J Lancaster19-Jan-10 22:30
professionalGarth J Lancaster19-Jan-10 22:30 
GeneralRe: Switching on and setting baud rate Pin
Richard MacCutchan20-Jan-10 0:43
mveRichard MacCutchan20-Jan-10 0:43 
GeneralRe: Switching on and setting baud rate Pin
CPallini20-Jan-10 3:01
mveCPallini20-Jan-10 3:01 
GeneralRe: Switching on and setting baud rate Pin
Richard MacCutchan20-Jan-10 3:30
mveRichard MacCutchan20-Jan-10 3:30 
AnswerRe: Switching on and setting baud rate Pin
Garth J Lancaster19-Jan-10 22:30
professionalGarth J Lancaster19-Jan-10 22:30 
GeneralRe: Switching on and setting baud rate Pin
CodeyBlank19-Jan-10 22:43
CodeyBlank19-Jan-10 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.