求大手帮忙一一解释下意思 急.#include "stdio.h"#include "stdlib.h"#include "windows.h"#define N 10 /*输入10个数*/struct d{int data;struct d * next;};typedef struct d D;D * creat(){int i;D *h,*s,*r;h=(D *)malloc(sizeof(D));r=h;srand(ti
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/24 08:12:09
![求大手帮忙一一解释下意思 急.#include](/uploads/image/z/12335135-23-5.jpg?t=%E6%B1%82%E5%A4%A7%E6%89%8B%E5%B8%AE%E5%BF%99%E4%B8%80%E4%B8%80%E8%A7%A3%E9%87%8A%E4%B8%8B%E6%84%8F%E6%80%9D+%E6%80%A5.%23include+%22stdio.h%22%23include+%22stdlib.h%22%23include+%22windows.h%22%23define+N+10+%2F%2A%E8%BE%93%E5%85%A510%E4%B8%AA%E6%95%B0%2A%2Fstruct+d%7Bint+data%3Bstruct+d+%2A+next%3B%7D%3Btypedef+struct+d+D%3BD+%2A+creat%28%29%7Bint+i%3BD+%2Ah%2C%2As%2C%2Ar%3Bh%3D%28D+%2A%29malloc%28sizeof%28D%29%29%3Br%3Dh%3Bsrand%28ti)
求大手帮忙一一解释下意思 急.#include "stdio.h"#include "stdlib.h"#include "windows.h"#define N 10 /*输入10个数*/struct d{int data;struct d * next;};typedef struct d D;D * creat(){int i;D *h,*s,*r;h=(D *)malloc(sizeof(D));r=h;srand(ti
求大手帮忙一一解释下意思 急.
#include "stdio.h"
#include "stdlib.h"
#include "windows.h"
#define N 10 /*输入10个数*/
struct d
{
int data;
struct d * next;
};
typedef struct d D;
D * creat()
{
int i;
D *h,*s,*r;
h=(D *)malloc(sizeof(D));
r=h;
srand(time(0));
for(i=0;idata=rand()%100;
r->next=s;
r=s;
}
r->next='\0';
return h;
}
void sort(D *h)
{
int t;
D *z,*y,*r;
z=h->next;
while(z->next!='\0')
{
y=z->next;
while(y->next!='\0')
{
if(z->data < y->data)
{
t=z->data;
z->data = y->data;
y->data = t;
}
y=y->next;
}
if(z->data < y->data)
{
t=z->data;
z->data = y->data;
y->data = t;
}
z=z->next;
}
}
void out(D *h)
{
int i;
D *s;
s=h->next;
while(s)
{
printf("%d\n",s->data);
s=s->next;
}
}
void ins(int n )
{
}
void dele()
{
}
int fun(int n)
{
}
main()
{
D *head;
head=creat();
out(head);
sort(head);
printf("排序后:\n");
out(head);
}
求大手帮忙一一解释下意思 急.#include "stdio.h"#include "stdlib.h"#include "windows.h"#define N 10 /*输入10个数*/struct d{int data;struct d * next;};typedef struct d D;D * creat(){int i;D *h,*s,*r;h=(D *)malloc(sizeof(D));r=h;srand(ti
D * creat()
{
int i; D *h,*s,*r;
h=(D *)malloc(sizeof(D)); //动态申请内存 大小为结构体struct d所占内存大小
r=h; //结构体r指向h
srand(time(0)); //产生随即数种子
for(i=0;idata=rand()%100; //rand()%100 可以随即获得0 - 99的整数
r->next=s; //r->next指向s
r=s; //r指向s 即在尾部添加链表s
}
r->next='\0'; //添加结束符
return h; //链表头部地址
}
void out(D *h)
{
int i;
D *s;
s=h->next;
while(s) //s不指向空,就往下执行
{
printf("%d\n",s->data); //输出数据
s = s->next; //指向下一个链表单元
}
}
void sort(D *h)
{ //排序采用的是冒泡排序算法
int t;
D *z,*y,*r;
z=h->next;
while(z->next!='\0') //指针不为空
{
y=z->next; //y指向z->next
while(y->next!='\0') // y找出最大数
{
if(z->data < y->data) //比较大小
{
t=z->data; //数据交换
z->data = y->data;
y->data = t;
}
y=y->next;
}
if(z->data < y->data) //比较数据大小
{
t=z->data; //数据交换
z->data = y->data;
y->data = t;
} z=z->next; //指向下一个元素,继续比较
}
}