文档介绍:-
. z
. I . r . .
{
printf("输入第%d个结点数据域",i);
scanf("%d",&d);
if(d==0)break;
if(i==1)
{
h=(nodetype *)malloc(sizeof(nodetype));
h->data=d;h->ne*t=NULL;t=h;
}
else
{
s=(nodetype *)malloc(sizeof(nodetype));
s->data=d;s->ne*t=NULL;t->ne*t=s;
t=s;
}
i++;
}
return h;
}
void sat(nodetype *h,int a[])
{
nodetype *p=h;
while(p!=NULL)
{
a[p->data]++;
p=p->ne*t;
}
}
void main()
{
int a[N+1],i;
for(i=0;i<N;i++)
a[i]=0;
nodetype *head;
head=create();
sat(head,a);
printf("候选人:");
for(i=1;i<=N;i++) printf("%3d",i);
printf("\n得票数\n");
for(i=1;i<=N;i++)
printf("%3d",a[i]);
printf("\n");
}
实验小结
-
. z
. I
. . r . .
线性表是最简单的、最常用的一种数据构造,是实现其他数据构造的根底。
实验二 栈与队列
实验要求
了解栈和队列的特性,以便灵活运用。
熟练掌握栈和有关队列的各种操作和应用。
实验容
设一个算术表达式包括圆括号,方括号和花括号三种括号,编写一个算法判断其中的括号是否匹配。
实验代码
:
#include<>
#include<>
#include<>
#define NULL 0
typedef struct list
{
char str;
struct list *ne*t;
}list;
void push(char,list *);
int pop( *);
void deal(char *str);
main(void)
{
char str[20];
printf("\n请输入一个算式:\n");
gets(str);
deal(str);
printf("正确!");
getchar();
return 0;
}
void deal(char *str)
{
list *L;
L=(list *)malloc(sizeof(list));
if(!L)
{
-
. z
. I
. . r . .
printf("错误!");
e*it(-2);
}
L->ne*t=NULL;
while(*str)
{
if(*str=='('|