C语言链表的转置算法,c语言编程集 数据结构 顺序表 点链表 数制转换 矩阵转置.doc...
c語言編程集 數據結構 順序表 點鏈表 數制轉換 矩陣轉置
#include "stdio.h"
#include "malloc.h"
/*typedef struct {
int *elem;
int length;
int listsize;
}sqlist;*/
void compare(int *p,int *q,int a,int b){
int *elem,*fadd;
int *pl=p+a;
int *ql=q+b;
elem=(int *)malloc(sizeof(int));
fadd=elem;
while((p<=pl)&&(q<=ql)){
if(*p<=*q){
*elem=*p;
elem++;
p++;
}
else{
*elem=*q;
q++;
elem++;
}
}
while(p<=pl){ *elem++=*p++; }
while(q<=ql){ *elem++=*q++; }
while(fadd<=elem-1){
printf("%d\n",*fadd);
fadd++;
}
}
main(){
int a[3]={1,2,3};
int b[3]={1,2,3};
compare(a,b,2,2);
}
#include "stdio.h"
#include "malloc.h"
#define sizep 3
typedef struct {
int *elem;
int length;
int listsize;
}sqlist;
sqlist scant(sqlist *p){
printf("請輸入串長度:");
scanf("%d",&(*p).length);
//scanf("%d",&(*p).listsize);
(*p).elem=(int *)malloc(sizeof(int));
return *p;
}
sqlist shuru(sqlist *m){
int *p=(*m).elem;
while(p<=(*m).elem+(*m).length-1){
scanf("\n%d",p);
p++;
}
p=(*m).elem;
/*while(p<=(*m).elem+(*m).length){
printf("%d\n",*p);
p++;
}*/
}
void compare(sqlist *p,sqlist *q){
sqlist r;
int *fadd;
int *pl=(*p).elem+(*p).length-1;
int *ql=(*q).elem+(*q).length-1;
r.length=(*p).length+(*q).length;
r.elem=(int *)malloc(sizeof(int));
fadd=r.elem;
//printf("%d",r.elem);
while((*p).elem<=pl&&(*q).elem<=ql){
if(*((*p).elem)<=*((*q).elem)){
*(r.elem)=*((*p).elem);
r.elem++;
(*p).elem++;
}
else{
*(r.elem)++=*((*q).elem)++;
}
}
while((*p).elem<=pl){
*(r.elem)++=*((*p).elem)++;
}
while((*q).elem<=ql){
*(r.elem)++=*((*q).elem)++;
}
//printf("%d\n",*fadd+1,fadd+r.length-1);
//printf("%d",fadd+r.length-1);
printf("排序數組為:");
while(fadd<=r.elem-1){
printf("%-3d",*fadd);
fadd=fadd+1;
}
printf("\n");
}
main(){
sqlist p,q,r;
scant(&p);
shuru(&p);
scant(&q);
shuru(&q);
compare(&p,&q);
}
#include "stdio.h"
#include "malloc.h"
#define max 101
typedef struct lnode{
int data;
int i,j;
}syz;
typedef struct {
in
總結
以上是生活随笔為你收集整理的C语言链表的转置算法,c语言编程集 数据结构 顺序表 点链表 数制转换 矩阵转置.doc...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微软:动视暴雪并非索尼 PlayStat
- 下一篇: c语言释放整个链表,最简单的链表删除第一