C语言 堆栈的建立
来源:互联网 发布:金山软件总公司怎么样 编辑:程序博客网 时间:2024/05/17 09:33
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
struct chain
{
int data;
struct chain *next;
};
struct chain *push(int n, int *data1)
{
struct chain *top,*s;
top=NULL;
int i;
for ( i =0;i<n;i++)
{
s = (struct chain *)malloc(sizeof(struct chain));
s->data = data1[i];
s->next = top;
top =s ;
}
return top;
}
int main (void)
{
int n,i;
struct chain *p;
printf("Enter a number n : ");
scanf("%i",&n);
srand((unsigned)time(NULL));
int a[n];
for (i=0;i<n;i++)
a[i]=rand()%100+1;
for (i=0;i<n;i++)
printf("%4i",a[i]);
printf("\n");
p = push(n,a);
while (p!=NULL)
{
printf("%4i",p->data);
p=p->next;
}
printf("\n");
return 0;
}
测试:
[root@localhost Gcc]# ./a.out
Enter a number n : 10
40 52 85 34 94 41 81 33 4 92
92 4 33 81 41 94 34 85 52 40
[root@localhost Gcc]# ./a.out
Enter a number n : 20
18 95 61 88 74 87 79 18 82 95 14 79 23 2 52 6 62 74 25 5
5 25 74 62 6 52 2 23 79 14 95 82 18 79 87 74 88 61 95 18
- C语言 堆栈的建立
- C语言的堆栈
- c语言的堆栈
- 堆栈的c 语言实现
- C语言的堆栈问题
- c语言的堆栈机制
- C 语言堆栈的实例
- C语言堆栈的讨论
- C语言堆栈的区别
- c语言--堆栈的区别
- 堆栈的C语言实现
- C语言实现堆栈(栈)的数据结构
- C语言 数据结构 堆栈的压栈出栈实例
- C语言函数堆栈的思考
- C语言函数堆栈的思考
- c语言中堆栈的简单理解
- C语言里面堆栈的区别
- 堆栈数据结构的C语言实现
- 九度online judge-开门人和关门人
- BZOJ 1002 FJOI 2007 轮状病毒 暴力+找规律+高精度
- UITableView 最详细和最经典的讲解方法
- 让程序员失去编程激情的5件事
- 操作系统文件管理
- C语言 堆栈的建立
- HTTP协议基础及分析工具使用
- OpenSSL中crypto的简单应用(命令篇)
- Hadoop-2.2.0中文文档—— Common - 超级用户模拟别的用户
- JavaScript之精确计算
- 程序员的路----程序员一定要仔细看
- POJ 1088 sking
- Log详解(Log.v,Log.d,Log.i,Log.w,Log.e)的用法
- sizeof的一个题目