c语言中的程序看不懂

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:12:20
帮忙看一下这个程序,我实在是看的不是太懂,顺便解释一下它的思路,谢谢了
#include<stdio.h>
#include<stdlib.h>
int max=0;
struct listnode
{
int value;
struct listnode *nextptr;
};
typedef struct listnode LIST;
typedef LIST * LISTPTR;
void swap(LISTPTR,LISTPTR);
void insert(LISTPTR *sptr,int a)
{
LISTPTR newptr,preptr;
newptr=malloc(sizeof(LIST));
if(newptr!=NULL){
max+=1;
newptr->value=a;
newptr->nextptr=NULL;
if((*sptr)==NULL)
*sptr=newptr;
else{
preptr=(*sptr);
while(preptr->nextptr!=NULL)
preptr=preptr->nextptr;
preptr->nextptr=newptr;
}
}
else
printf("error\n");
}
void bobble(LISTPTR sptr,int total)
{
int i;
LISTPTR preptr,couptr;
preptr=sptr;
couptr=sptr->nextptr;
for(i=1;i<=total-1;i++){
while

这是一个对链表进行一系列处理的程序,进入程序后,调用instruction()函数,显示菜单:
1.insert a value
2.print listnode
3.exit
接着进入一个无限的循环:
while(1){...}
输入1,可以调用
insert(&startptr,b)
在链表尾部插入一个新的节点

输入2,调用
bobble(startptr,max)
函数,进行冒泡排序,并输出链表

输入3,退出