数据结构在进栈和出栈的时候有错!!帮忙改一下
// Stack.cpp : Defines the entry point for the console application.//
//头文件包含区
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
//数据类型定义
struct Node{
int data;
Node* next;
};
struct LStack{
Node* top;
int length;
};
//操作函数定义
void InitLstack(LStack &ls)
{
ls.top= 0;
ls.length = 0;
}
//入栈操作
void PushLstack(LStack &ls, int e)
{
Node s;
s.data = e;
s.next = 0;
s.next = ls.top;
ls.top = &s;
ls.length++;
}
void PopLstack(LStack &ls, int &e)
{
if(ls.length<=0)
return;
e = ls.top->data;
Node * p;
p = ls.top;
ls.top = ls.top->next;
ls.length--;
return;
}
void prinfLstack1(LStack lss)
{
Node* p = lss.top;
while(p)
{
printf("%d ",p->data);
p = p->next;
}
}
void prinfLstack(LStack lss)
{
int e;
while(lss.length)
{
PopLstack(lss,e);
printf("%d ",e);
}
}
//主函数试验区
int main(int argc, char* argv[])
{
int k=5;
LStack lss;
InitLstack(lss);
while(k!=-1)
{
scanf("%d",&k);
PushLstack(lss,k);
}
prinfLstack1(lss);
return 0;
}