c语言万能编程模板_有用c语言编写程序的模板吗

2009-04-19 回答

#include"stdio.h"

#include"stdlib.h"

typedef struct Node

{

int data;

struct Node *next;

}NODE;

typedef struct

{

NODE *top;

}Stack;

#define TRUE 1

#define FALSE 0

#define OK 1

#define OVERFLOW -2

typedef int Status;

void InitStack(Stack &S)

{

S.top=(NODE *)malloc(sizeof(NODE));

if(!S.top)

exit(OVERFLOW);

S.top->next=NULL;

}

Status StackEmpty(Stack S)

{

if(S.top->next==NULL)

return(TRUE);

else return(FALSE);

}

void Push(Stack &S,int e)

{

NODE *p;

p=(NODE *)malloc(sizeof(NODE));

if(!p)

return;

p->data=e;

p->next=S.top->next;

S.top->next=p;

}

void Pop(Stack &S,int &e)

{

NODE *p;

if(StackEmpty(S))

return;

else

{

p=S.top->next;

e=p->data;

S.top->next=p->next;

free(p);

}

}

int Gettop(Stack &S)

{

NODE *p;

if(StackEmpty(S))

return(0);

else

{

p=S.top->next;

return(p->data);

}

}

#include "linksq.h"

void main()

{

int select;

int num=1,e;

Stack S;

InitStack(S);

do{

printf("\n1 Push 2 Pop\n");

printf("0 exit\n please select(0--2)\n");

scanf("%d",&select);

switch(select)

{

case 1:

printf("Push%2d",num);

Push(S,num++);

break;

case 2:

if(!StackEmpty(S))

{

Pop(S,e);

printf("Pop %2d ",e);

}

else

printf("Empty!\n");

break;

case 0:

break;

}

}

while(select);

}

这是c语言版的数据结构的一段程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值