清风小天鹅 2021-06-10 11:52 采纳率: 100%
浏览 61
已采纳

为啥用vs2012报错,用DevC++却不报错

数据结构做链式堆栈遇到了这个问题,以下是我的代码。看了好久都没有发现错误。以下是本人的代码:

// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;

typedef int ElemType;
typedef struct Node
{
	ElemType data;
	struct Node *next;
}*Listack;

void InitListack(Listack &top)
{
	top=NULL;
}

void Push(Listack &top,ElemType e)
{
	Node *s;
	s=new Node();
	s->data=e;
	s->next=top;
	top=s;
}

void Pop(Listack &top)
{
	ElemType e;
	Node *p=top;。
	if(top==NULL)
	{
		cout<<"栈空"<<endl;
	}else
	{
		e=top->data;
		top=top->next;
		delete p;
	}
}

void ShowLiStack(Listack &top)
{
	Listack p;
	p=NULL;
	p=top;
	while (p!=NULL)
	{
		cout<<p->data<<"";
		p=p->next;
	}
}


int _tmain(int argc, _TCHAR* argv[])
{
	Listack Ls;
	cout<<"请输入你要插入的位数(大于等于1)"<<endl;
	int n;
	cin>>n;
	if (n<=0)
	{
		cout<<"非法值,重新输入"<<endl;
	}
	for (int i = 0; i < n; i++)
	{
		cout<<"请输入你想输入的第"<<i+1<<"个值"<<endl;
		int e;
		cin>>e;
		Push(Ls,e);
	}
	ShowLiStack(Ls);
	cout<<"打印完成"<<endl;
	getchar();
	getchar();


	return 0;
}


  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-06-10 11:55
    关注

    Listack Ls;

    InitListack(Ls);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)