Data Structure:stack

本文通过C语言代码示例介绍了如何使用线性表来实现栈的数据结构,并演示了栈的基本操作如压栈、弹栈及显示栈内元素。

   using  linear list to realize the Stack,code as the following:

// STACK.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<malloc.h>
struct stackpoint{
int data;
 stackpoint *next;
} *top=NULL;

int stackin(int data){
	stackpoint *h1=(stackpoint *)malloc(sizeof (stackpoint));h1->data=data;
	if(top==NULL){top=h1;h1->next=NULL;return 1;}
	stackpoint *h2=top;
	while(h2->next!=NULL){h2=h2->next;}
	h1->next=top;
	top=h1;
}
int stackdel(){
	stackpoint *h1=top;
	top=top->next;
	free(h1);
	return 1;
}
void stackdply(){
	stackpoint *h1=top;
	while(h1->next!=NULL){printf("%d\t",h1->data);h1=h1->next;}printf("%d\n",h1->data);
}

int main(int argc, char* argv[])
{	stackin(2);stackin(3);stackin(4);stackin(5);
	stackdply();
	stackdel();
	stackin(9);
	stackdply();
	stackdel();
	stackdply();
	return 0;
}
It is useful for me to learn the  Data Structure,first simple footmark  XD.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值