Skip to content
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

Merged
merged 5 commits into from
Apr 10, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions 2017-1/Cloud/2-12.cpp
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 ;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仅接受C语言版的代码实现,不接受C++代码
建议使用后缀名.c去调试无误后再行提交

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问还有需要修改的部分吗~~结构体部分c++代码已经改正了。

}LNode,*LinkList;
void travle(LinkList &L_){

printf("��������:");
LinkList p = L_->next ;
for(int i = 0 ;i <length;i++){
//printf("%d ",(L_+i)->data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

循环结束条件设置有误,请重新考虑链表遍历方法

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;//������һ�������ɵĽ������ȥ��
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意代码格式化,建议使用VS自动格式化代码

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
//}

}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用随机函数产生链表数据,不要手工输入

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意缩进和代码格式化

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return 0;
}