去数据结构随便找下都有,
我现在的电脑里面没了,都是重装系统惹的祸,
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct student
{char name[80];
int a,b;
struct student *next;
}*creat();
struct student *creat()
{struct student *head=NULL,*tail=NULL,*p,*pp;
char name[80];
int a,b;
int size=sizeof(struct student);
scanf("%s%d%d",name,&a,&b);
while (a!=0){
p=(struct student *)malloc(size);
p->a=a;p->b=b;p->next=NULL;
strcpy(p->name,name);
if (head==NULL)
head=tail=p;
else
tail->next=p;
tail=p;
scanf("%s%d%d",name,&a,&b);}
for (pp=head;pp;pp=pp->next)
printf("%-7s%-5d%-5d\n",pp->name,pp->a,pp->b);
return (head);
}
void main()
{struct student *head;
head=creat();
}
这是一个单向链表,请问怎么改就变成双向链表呢?
#include "stdlib.h"
#include "string.h"
struct student
{char name[80];
int a,b;
struct student *rlink,*llink;
};
struct student *creat(void)
{
struct student *head=NULL,*tail=NULL,*p,*pp;
char name[80];
int a,b;
int size=sizeof(struct student);
scanf("%s%d%d",name,&a,&b);
while (a!=0){
p=(struct student *)malloc(size);
p->a=a;p->b=b;p->rlink=p->llink=NULL;
strcpy(p->name,name);
if (head==NULL)
head=tail=p;
else
{
tail->rlink=p;
p->llink=tail;
}
tail=p;
scanf("%s%d%d",name,&a,&b);}
for (pp=head;pp;pp=pp->rlink)
printf("%-7s%-5d%-5d\n",pp->name,pp->a,pp->b);
return (head);
}
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int info;
struct node *front;
struct node *rear;
};
node *creat()
{
node *head,*pre,*p;
int num;
head=(node *)malloc(sizeof(node));
pre=head;
printf("输入关键值:");
scanf("%d",&num);
while(num!=-1)
{
p=(node*)malloc(sizeof(node));
p->info=num;
pre->rear=p;
p->front=pre;
p->rear=NULL;
pre=p;
printf("输入关键值:");
scanf("%d",&num);
}
pre->rear=NULL;
return(head);
}
void Display(node *head)
{
node *p=head->rear;
printf("打印链表:");
while(p!=NULL)
{
printf("%d---->",p->info);
p=p->rear;
}
printf("^\n");
}
/*int main()
{
node *head;
head=creat();
Display(head);
return(0);
}*/