//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "string.h"
#include "time.h"
#include "stdlib.h"
struct STU{
int stuid;
char name[20];
char sex;
double grade;
struct STU *next;
};
void mysort(struct STU *p){
struct STU t,*q,*r;
for(;p;p=p->next){
for(q=p,r=q->next;r;r=r->next)
if(q->gradegrade)
q=r;
if(q!=p){
t=*p;
*p=*q;
p->next=t.next;
r=q->next;
*q=t;
q->next=r;
}
}
}
struct STU *delnode(struct STU *p,double a,double b){
struct STU *t,tmp;
for(tmp.next=p,p=&tmp;p->next;)
if(p->next->grade>=a && p->next->grade<=b){
t=p->next->next;
free(p->next);
p->next=t;
}
else p=p->next;
return tmp.next;
}
void freenode(struct STU *p){
if(p->next) freenode(p->next);
free(p);
}
int main(void){
int i,k,x,id=10000000;
double a,b;
struct STU *head,*p;
char t[11][10]={"张三","李四","王五","赵六","孟七","周二","钱一","魏八","吴九","匡十",""};
if((p=head=(struct STU *)malloc(sizeof(struct STU)))==NULL){
printf("Establish a head node failure...");
return NULL;
}
srand((unsigned)time(NULL));
for(x=10,i=0;i<10;i++){
if((p->next=(struct STU *)malloc(sizeof(struct STU)))==NULL){
printf("Failed to create node...");
freenode(head);
return NULL;
}
p->next->stuid=id++;
strcpy(p->next->name,t[k=rand()%x--]);
strcpy(t[10],t[k]);
strcpy(t[k],t[x]);
strcpy(t[x],t[10]);
p->next->sex = rand()%2 ? 'f' : 'm';
p->next->grade=(rand()%600+401)/10.0;
p=p->next;printf("%d %s %c %g\n",p->stuid,p->name,p->sex,p->grade);
}
p->next=NULL;
p=head;
head=head->next;
free(p);
mysort(head);
printf("\n\n");
for(p=head;p;p=p->next)
printf("%d %s %c %g\n",p->stuid,p->name,p->sex,p->grade);
printf("\n\n");
while(1){
printf("Please enter the scope to delete(double 0 if(scanf("%lf%lf",&a,&b),a>0 && a break;
printf("Error, redo: ");
}
head=delnode(head,a,b);
for(p=head;p;p=p->next)
printf("%d %s %c %g\n",p->stuid,p->name,p->sex,p->grade);
freenode(head);
return 0;
}
自己写一部分代码,调试不通的话,我可以帮你调试。
你好!链表最大容量是10个节点,程序什么时间要呢
每个节点还是一个结构
#include
#include
#include
typedef struct Info
{
char xuehao;
char *xingming;
char *xingbie;
int chengji;
}Stu;
typedef struct Node
{
Stu *data;
Node *next;
}NODE,*LinkedList;
char Xuehao[10] ={'1','2','3','4','5','6','7','8','9','0'};
char *Xingming[10] ={"小赵","小钱","小孙","小李""小周","小吴","小郑","小王","小张","小小"};
char *Xingbie[2] ={"男","女"};
int Chengji[] ={11,22,33,44,55,66,77,88,99,100};
//初始化
LinkedList Initiallist()
{
NODE *head,*p,*L;
head = (NODE *)malloc(sizeof(NODE));
L=head;
int i;
for (i=0;i<10;i++)
{
p=(NODE *)malloc(sizeof(NODE));
p->data->xuehao = Xuehao[i];
p->data->chengji=Chengji[i];
p->data->xingming=Xingming[i];
p->data->xingbie = Xingbie[i%2];
L->next = p;
L=p;
}
return head;
}
LinkedList paixu(NODE *L)
{
int x,y,i;
NODE *p=L;
for (i=0;i<10;i++)
{
x=p->data->chengji;
y=p->next->data->chengji;
if(x
p->data->chengji = y;
p->next->data->chengji = x;
}
p=p->next;
}
return L;
}
LinkedList shanchu(NODE *L)
{
int x,y,i;
NODE *p=L;
scanf("%d%d",&x,&y);
for (i=0;i<10;i++)
{
if(p->next->data->chengji>=x &&p->next->data->chengji<=y)
{
NODE *q=(NODE *)malloc(sizeof(NODE));
q=p;
p->next=p->next->next;
free(q);
}
}
return L;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
我没测试,写的比较简单。大致就是这样。