① c语言链表:填空题,我只写了sort()函数,目的是将结点按num顺序排列的。函数错了,怎么改还
sort 函数里面 prev =head->next;
prev->next = null;//出错的关键是这句。让head->next->next = null了。
p = head->next; //相当于 p ->next =null了
进入一次循环,p = p ->next ; p == null了 ;直接跳出循环了
② 急救!!C语言一道关于结构体链表的填空题,就一个空
上面那位大哥,你出现了一个小错误,我改了一下p = pa; //将p指针指向首地址
printf("%c", p.value); 不知你结构另外一个成员是哪个,就当value了,别的你改
p = p->next; //1楼指针应该用指针成员
③ c语言 链表 填空 速度追加给分
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}Linknode;
//创建一个链表,其数据元素为2,4,2,8,3,2,2
Linknode *create()
{
Linknode * head,*p,*n;
int temp=0;
head=(Linknode *)malloc(sizeof(Linknode));
head->next=NULL;
p=head;//head is first node
while(1){
scanf("%d",&temp);
if(!temp)break;
n=(Linknode *)malloc(sizeof(Linknode));
n->data=temp;
n->next=NULL;
p->next=n;
p=n;
}
return head;
}
int print(Linknode *h)
{
Linknode *p;
p=h->next;
while(p){
printf("%d,",p->data);
p=p->next;
}
return 0;
}
//计算数据域为x的节点个数
int countx(Linknode *h,int x)
{
Linknode *p;
int count=0;
/***********SPACE***********/
p=h->next;
while(p){
/***********SPACE***********/
if(x==p->data)
/***********SPACE***********/
count++;
/***********SPACE***********/
p=p->next;
}
return count;
}
int main()
{
Linknode *head;
int m;
head=create();
print(head);
printf("\n------------------\n");
m=countx(head,2);
printf("共%d个元素",m);
system("pause");
return 0;
}
④ c语言编程问题 链表
链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。
链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成。
每个结点包括两个部分:
1、存储数据元素的数据域;
2、存储下一个结点地址的指针域。
在C语言中,链表的构建是通过结构体实现的,一个结构体变量,形成一个链表的节点。
在结构体内,需要由至少一个类型为结构体本身类型的指针的元素,作为指针域存在,用来指向下一个或者上一个(仅用于双向链表)元素节点。
⑤ C语言 链表 这个题目怎么做
#include<stdio.h>
#include<malloc.h>
structlist{
intID;
structlist*next;
};
structlist*CreateList(){
intnum,i;
structlist*head,*p;
scanf("%d",&num);//num:链表结点个数
head=p=(structlist*)malloc(sizeof(structlist));//这是链表的头结点
i=0;
while(i<num){
p->next=(structlist*)malloc(sizeof(structlist));
scanf("%d",&p->next->ID);
p=p->next;
i++;
}
p->next=NULL;
return(head);
}
intmain(){
structlist*head;
head=CreateList();
return0;
}
⑥ 链表习题(C语言)
设链表长度为n,找到倒数第m个元素(约定0为最后一个元素),也就是找到正数第n - m - 1个元素,计数方法当然也是从0开始。
#include<stdio.h>
#include<stdlib.h>
typedefintDataType;
typedefstructlist{
DataTypeelem;
structlist*next;
}*LIST,*pNode;
LISTInitList(){
LISTL=(pNode)malloc(sizeof(structlist));
L->elem=0;
L->next=NULL;
returnL;
}
voidCreateList(LISTL,DataTypea[],intn){
inti;
pNodep=L;
for(i=0;i<n;++i){
p->next=(pNode)malloc(sizeof(structlist));
p->next->elem=a[i];
p=p->next;
}
p->next=NULL;
}
intlenList(LISTL){//求取表长
intlen=0;
pNodep=L->next;//有头结点
while(p){++len;p=p->next;}
returnlen;
}
intGetData(LISTL,intm,DataType*e){
inti=-1,len=lenList(L);
pNodep=L->next;
if(m<0||m>len-1){
printf("没有第%d个元素。 ",m);
return0;
}
while(i<len-m-1){++i;p=p->next;}
*e=p->elem;
return1;
}
intmain(){
DataTypearr[]={16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
intn,m,res;
LISTL=InitList();
n=sizeof(arr)/sizeof(arr[0]);
CreateList(L,arr,n);
while(scanf("%d",&m)==1){
if(GetData(L,m,&res))
printf("倒数第%d元素是:%d. ",m,res);
}
return0;
}
⑦ 关于链表的程序填空
(1)struct node *p,*q; //当然是先定义两个struct node 型的指针
(2)count++; //count自增,直到与k相等时退出循环
(3)p=p->next; //当与q指针相差k个结点时,p、q指针同步移动。
(4)q->data; //返回该结点的data域值
答案绝对正确,绝非网上搜索答案,本人是C语言驱动工程师。给分,谢谢
⑧ C语言链表填空,求大佬
楼主,你要的答案
#include <stdio.h>
#include <math.h>
void fun(int *a,int n,int *odd,int *even){
for(int i=0;i<n;i++){
if(a[i]%2==0)
*even+=a[i];
else
*odd+=a[i];
}}
void main(){
int a[5];
int *even;
int *odd;
int x=0,y=0;
odd=&x;
even=&y;
printf("请输入数组a的值\n");
for(int i=0;i<5;i++)
scanf("%d",&a[i]);
fun(a,5,even,odd);
printf("偶数和为%d,奇数和为%d",*even,*odd);
}
⑨ 一道C语言链表题
#include<stdio.h>
#include<malloc.h>
/*UserCodeBegin(考生可在本行后添加代码,定义程序中使用的结构体类型、声明自定义函数的原型,行数不限)*/
structstudent
{intnum,score;
structstudent*next;
};
structstudent*creat();
structstudent*merge(structstudent*ah,structstudent*bh);
/*UserCodeEnd(考生添加代码结束)*/
/*print以规定的格式完成遍历显示指定的链表*/
voidprint(char*Info,structstudent*Head);
intmain(void)
{
structstudent*ah,*bh;
printf("创建链表A,请输入学号及成绩(均输入为0时表示停止):
");
ah=creat();
printf("
创建链表B,请输入学号及成绩(均输入为0时表示停止):
");
bh=creat();
print("
链表A:",ah);
print("
链表B:",bh);
ah=merge(ah,bh);
print("
链表A、B合并后:",ah);
return0;
}
voidprint(char*Info,structstudent*Head)
{
printf("%s",Info);
while(Head!=NULL)
{
printf("%d,%d",Head->num,Head->score);
Head=Head->next;
}
}
/*UserCodeBegin(考生在此后完成自定义函数的设计,行数不限)*/
structstudent*creat()
{structstudent*h,*p,*H;
intxh,cj,b=1;
do
{scanf("%d%d",&xh,&cj);
if(xh==0&&cj==0)break;
h=(structstudent*)malloc(sizeof(structstudent));
h->num=xh;h->score=cj;
if(b){b=0;H=h;}
elsep->next=h;
p=h;
}while(1);
h->next=NULL;
returnH;
}
structstudent*merge(structstudent*ah,structstudent*bh)
{structstudent*p=ah;
while(p->next!=NULL)p=p->next;
p->next=bh;
returnah;
}
⑩ C语言程序填空:假设有两个已排序的单链表a,b,现将它们合并成一个链表c,且不改变其有序性。
你不是有答案吗,你想要什么