-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
作业2-12-Cloud #30
作业2-12-Cloud #30
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#define length 10 | ||
typedef struct LNode{ | ||
int data; | ||
LNode *next ; | ||
}LNode,*LinkList; | ||
void travle(LinkList &L_){ | ||
|
||
printf("��������:"); | ||
LinkList p = L_->next ; | ||
for(int i = 0 ;i <length;i++){ | ||
//printf("%d ",(L_+i)->data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 循环结束条件设置有误,请重新考虑链表遍历方法 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已改 |
||
printf("%d ",p->data ); | ||
p = p->next ; | ||
} | ||
printf("\n"); | ||
} | ||
void CreatList(LinkList &L,int n){ | ||
LNode *p; | ||
L = (LinkList)malloc( sizeof(LNode) ); | ||
L->next = NULL;//������������ͷ��� | ||
if(L) | ||
printf("ͷ�ڵ㴴���ɹ���\n"); | ||
for(int i = n; i > 0;--i){ | ||
p = (LinkList)malloc(sizeof(LNode)); | ||
if(p) | ||
printf("�ɹ�����һ���ڵ�ռ䣬������һ��������"); | ||
scanf("%d",& p->data ); | ||
p->next = L->next ;//��һ������ʱL->next����һ�β���Ľڵ���������������� | ||
L->next = p;//������һ�������ɵĽ������ȥ�� | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意代码格式化,建议使用VS自动格式化代码 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
travle(L); | ||
//printf("����һ����������"); | ||
//for(int i ;i <length;i++){ | ||
// printf("%d",L+i); | ||
//} | ||
|
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用随机函数产生链表数据,不要手工输入 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已改 |
||
|
||
void MergeList(LinkList &La,LinkList &Lb,LinkList &Lc){ | ||
LinkList pa,pb,pc; | ||
pa = La->next ; | ||
pb = Lb->next ; | ||
Lc = pc = La; | ||
while(pa && pb){ | ||
if( pa->data <= pb->data ){ | ||
pc->next = pa; | ||
pc = pa; | ||
pa = pa->next ; | ||
} | ||
else{ | ||
pc->next = pb; | ||
pc = pb; | ||
pb = pc->next; | ||
} | ||
} | ||
pc->next = pa ? pa : pb; | ||
free(Lb); | ||
} | ||
|
||
int main(){ | ||
LinkList list_a,list_b,list_c; | ||
|
||
CreatList(list_a,length); | ||
CreatList(list_b,length); | ||
MergeList(list_a,list_b,list_c); | ||
travle(list_c); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意缩进和代码格式化 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
return 0; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
仅接受C语言版的代码实现,不接受C++代码
建议使用后缀名
.c
去调试无误后再行提交There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请问还有需要修改的部分吗~~结构体部分c++代码已经改正了。