您的位置:首页 > 编程语言 > C语言/C++

C++链表实现堆栈:LinkList:Build a linklist using C++ class Stack

2009-12-09 16:07 501 查看
// Stack.cpp : Defines the entry point for the console application.

#include

"stdafx.h"
#include

"iostream"
using

namespace std;
typedef

struct
_node

int

data;

struct

_node *next;

class

MyStack

private

:

public

:

while

(head)

delete

p;

void

Initialize(Node *h)

if

(head==NULL)

bool

Empty()

if

(head==NULL)

return true

;

else

return false

;

void

pushh(Node* h)

if

(head==NULL)

else

{

h->next=head;

head=h;

}

}

int

pop()

if

(head==NULL)

return

-1;

else

{

int

val=head->data;

return

val;

return

head;

void

_tmain(int

argc, _TCHAR* argv[])

sizeof

(Node));

sizeof

(Node));

if

(s.Empty())

"the stack is empty"

<<endl;

else

cout<<s.top()->data;

cin.get();

}

cout<<

ph->data=2;

s.pushh(ph);

s.pop();

p->data=1;

p->next=NULL;

s.Initialize(p);

Node* ph=(Node*)malloc(

{

MyStack s;

Node* p=(Node*)malloc(

}

};

}

}

Node* top()

{

head=head->next;

{

head=h;

{

}

{

head=h;

}

{

}

}

{

Node *p=head;

head=head->next;

MyStack()

{

head=NULL;

}

~MyStack()

{

Node* head;

{

}Node;

{

//
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: