这是我在学习数据结构遇到的第一个问题,汗,刚刚开始就遇到了麻烦,感觉很是不了解这几条语句的意思!
谁能个详细的讲解一下……
小弟在此提前谢谢各位来客了!
/*使用堆栈处理数据——新增、删除、输出*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define MAX 100
void push_f(void);
void pop_f(void);
void list_f(void);
char item[MAX][20];/*这一行也是不太懂*/
int top=-1;
void main(void)
{
char option;
while(1)
{
printf("/n**********************/n");
printf(" <1>insert(push)/n");
printf(" <2>delete(pop)/n");
printf(" <3>list/n");
printf(" <4>quit/n");
printf("*************************/n");
printf("Please enter your choice..");
option=getch();
switch(option)
{
case '1':push_f(); break;
case '2':pop_f(); break;
case '3':list_f(); break;
case '4':exit(0);
}
}
}
void push_f(void)
{
if(top>=MAX-1)
printf("/n/n Stack is full !/n");
else
{
top++;
printf("/n/nPlease enter item to insert:");
gets(item[top]);
}
}
void pop_f(void)
{
if(top<0)
printf("/n/n No item,Stack is empty!/n");
else
{
printf("/n/n Item %s deleted /n",item[top]);
top--;
}
}
void list_f(void)
{
int count=0,i;
if(top<0)
printf("/n/nNo item,Stack is empty/n");
else
{
printf("/n/n ITEM /n");
printf("---------- /n");
for(i=0;i<=top;i++)
{
printf(" %-20s/n",item[i]);/*谁能帮忙解释下这行语句啊?*/
count++;
if(count%20==0) getch();/*还有这一行*/
}
printf("------------/n");
printf("Total item:%d/n",count);
getch();
}
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define MAX 100
void push_f(void);
void pop_f(void);
void list_f(void);
char item[MAX][20];/*这一行也是不太懂*/
int top=-1;
void main(void)
{
char option;
while(1)
{
printf("/n**********************/n");
printf(" <1>insert(push)/n");
printf(" <2>delete(pop)/n");
printf(" <3>list/n");
printf(" <4>quit/n");
printf("*************************/n");
printf("Please enter your choice..");
option=getch();
switch(option)
{
case '1':push_f(); break;
case '2':pop_f(); break;
case '3':list_f(); break;
case '4':exit(0);
}
}
}
void push_f(void)
{
if(top>=MAX-1)
printf("/n/n Stack is full !/n");
else
{
top++;
printf("/n/nPlease enter item to insert:");
gets(item[top]);
}
}
void pop_f(void)
{
if(top<0)
printf("/n/n No item,Stack is empty!/n");
else
{
printf("/n/n Item %s deleted /n",item[top]);
top--;
}
}
void list_f(void)
{
int count=0,i;
if(top<0)
printf("/n/nNo item,Stack is empty/n");
else
{
printf("/n/n ITEM /n");
printf("---------- /n");
for(i=0;i<=top;i++)
{
printf(" %-20s/n",item[i]);/*谁能帮忙解释下这行语句啊?*/
count++;
if(count%20==0) getch();/*还有这一行*/
}
printf("------------/n");
printf("Total item:%d/n",count);
getch();
}
}