-
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
the first upload #21
Merged
Merged
the first upload #21
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<stdio.h> | ||
#include"up1998.h" | ||
int main(void) | ||
{ | ||
LinkList La, Lb, Lc; | ||
LinkList test1��test2; | ||
int LENTH=5; | ||
La = (LinkList)malloc(sizeof(LNode)); //malloc() ���ص�������void * ��, ����ͬ�����Ͳ��ܽ��и�ֵ����, ����Ҫ����ǿ������ת�� | ||
CreateList_L(La, LENTH+rand()%5, test1);//����list | ||
printf("La:");//���la | ||
TraverseList_L(La, print); //����La | ||
printf("\n"); | ||
|
||
Lb = (LinkList)malloc(sizeof(LNode)); //malloc() ���ص�������void * ��, ����ͬ�����Ͳ��ܽ��и�ֵ����, ����Ҫ����ǿ������ת�� | ||
CreateList_L(Lb, LENTH+rand()%5, test2); //����list | ||
printf("Lb:"); //���lb | ||
TraverseList_L(Lb, print);//����lb | ||
printf("\n"); | ||
|
||
MergeList_L(La, Lb, &Lc); //�ϲ�һ��lc &Lc������ | ||
printf("Lc:"); //���lc | ||
TraverseList_L(Lc, print);//����lc | ||
printf("\n"); | ||
return 0; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include<stdio.h> //ͷ�ļ� | ||
#include<stdlib.h> //ͷ�ļ� | ||
|
||
typedef int ElemType; //�Զ���һ��������ElemType | ||
|
||
typedef struct LNode{ | ||
ElemType data; //int ������data | ||
struct LNode* next; | ||
}LNode,*LinkList; //�Զ���һ���������ṹ�� | ||
//struct Lnode��һ�����壬����Lnode��һ���ṹ�����ͣ���struct Lnode�ض���ΪLnode���Ժ�Ϳ��Բ���дstruct�ˣ�ֱ��ʹ��Lnode����ṹ�������ָ��ȵȡ� | ||
|
||
void scan(ElemType *p)//�Զ��庯�� ���� | ||
{ | ||
scanf("%d",p);//����list | ||
} | ||
void print(const ElemType n)//�Զ��庯�� ��� | ||
{ | ||
printf("%2d ",n); //�����ֽڴ�С ���list | ||
} | ||
|
||
void CreateList_L(LinkList , int , void(*)(ElemType*)); | ||
//�㷨2.11 �½������� | ||
|
||
void TraverseList_L(const LinkList,void(*)(ElemType)); | ||
//���ζ�Linklist��ÿ������Ԫ�ص��ú���void(*)(ElemType) | ||
void MergeList_L(LinkList, LinkList, LinkList); | ||
//�㷨2.12 �鲢���������� | ||
|
||
int test1_iter(int k)//����test1 | ||
{ | ||
static int b = 20; | ||
return b -= k; | ||
} | ||
void test1(ElemType *p)//��ʼ��test1��������� | ||
{ | ||
*p = test1_iter(rand() % 5+1); | ||
} | ||
|
||
int test2_iter(int k)//����test2 | ||
{ | ||
static int b = 20; | ||
return b -= k; | ||
} | ||
void test2(ElemType *p)//��ʼ��test2��������� | ||
{ | ||
*p = test2_iter(rand() % 5+1); | ||
} | ||
//����4���������ڲ�������������� | ||
|
||
|
||
|
||
void CreateList_L(LinkList L, int n, void(*func)(ElemType*))//�½����� | ||
{ | ||
LNode* p; //ָ�� | ||
L->next = NULL; //�����е�ָ����һ���ڵ㡣->�DZ�ʾָ��ṹ���еij�Ա | ||
for (int i = 0; i < n; ++i) | ||
{ | ||
p = (LinkList)malloc(sizeof(LNode));//malloc() ���ص�������void * ��, ����ͬ�����Ͳ��ܽ��и�ֵ����, ����Ҫ����ǿ������ת�� | ||
func(&p->data); | ||
p->next = L->next; | ||
L->next = p; //����һ���µĽڵ㣬��������뵽�������� | ||
} | ||
};//CraeteList_L | ||
//�½�����Ϊn�ĵ�����L��������ÿ������ʹ��func���������� | ||
|
||
|
||
void TraverseList_L(const LinkList L,void(*func)(ElemType))//���ζ�Linklist��ÿ������Ԫ�ص��ú���void(*)(ElemType) | ||
{ | ||
LNode *p = L->next; | ||
while (p)//�ɹ�ʱ | ||
{ | ||
func(p->data); //ִ��func���� | ||
p = p->next; //ָ��ָ����һ������Ԫ�� | ||
} | ||
} | ||
//����������L��������ÿ������ִ��func���� | ||
|
||
|
||
void MergerList_L(LinkList &La,LinkList &Lb,LinkList &Lc) | ||
{ //��֪�������Ա�La��Lb��Ԫ�ذ�ֵ�ǵݼ����� | ||
//�鲢La��Lb�õ��µĵ������Ա�Lc��Lc��Ԫ��Ҳ����ֵ�ǵݼ����� | ||
/* pa = La->next; | ||
pb = Lb->next; | ||
Lc = pc = La;*/ | ||
LNode *pa = La->next, *pb = Lb->next, *pc; //paָ��La���е�ǰ�Ƚϲ���Ľ�� pbָ��Lb���е�ǰ�Ƚϲ���Ľ�� | ||
(*Lc) = pc = La;// ��La��ͷ�����ΪLc��ͷ��㣬pcʼ��ָ��Lc��ǰ���һ����� | ||
while(pa && pb)//LaLbΪ�ǿձ� | ||
{ if(pa->data <= pb->data)//paָ��Ԫ��С��pbָ��Ԫ�� | ||
{pc->next = pa;//pc���pa��ָ��Ԫ�ص���һ�� | ||
pc = pa;//pc���pa��ָ��Ԫ�� | ||
// �ȼ��� pc = pc->next | ||
pa = pa->next;//pa���pa��ָ��Ԫ�ص���һ�� | ||
} | ||
else{ pc->next = pb;//paָ��Ԫ�ش���pbָ��Ԫ�� | ||
pc = pb; //pc���pb��ָ��Ԫ�� | ||
// �ȼ��� pc = pc->next | ||
pb = pb->next; //pb���pb��ָ��Ԫ�ص���һ�� | ||
} | ||
} | ||
pc->next = pa?pa:pb; | ||
// ����ʣ��Σ�?������Ŀ����� | ||
free(Lb); // �ͷ�Lb��ͷ��� | ||
}// MergeList L | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
请在代码运行通过后再次提交:
去调试无误后再行提交