问题描述:
#include
using namespace std;
const int MaxSize = 100;
typedef struct{
int *data;
int length;
}SeqList;
//顺序表初始化
void InitList(SeqList &L)
{
L.data = new int[MaxSize];
L.length=0;
}
//创建顺序表
void CreatList(SeqList &L)
{
int n;
cout<<"创建顺序表元素个数:" ;
cin>>n;
L.length = n;
for(int i=0;i>L.data[i];
}
}
//打印顺序表
void PrintList(SeqList L){
for(int i=0;i
程序运行结果:
问题描述:
代码实现如下:
#include
using namespace std;
typedef struct Node{
int data;
struct Node* next;
}LinkList;
//尾插创建单链表
struct Node* creatlist(){
Node* head = new Node;
head->next = nullptr;
Node* rear = head;
Node* s = nullptr;
int n;
cout<<"创建链表的长度:";
cin>>n;
cout<<"输入链表的值:" ;
for(int i=0;i>s->data;
rear->next = s;
rear = s;
}
rear->next = nullptr;
return head;
}
//打印单链表
void printfList(Node *head){
Node* pre = head->next;
while(head){
cout<data<<" ";
pre = pre->next;
}
cout<next;
lb = head2->next;
Node* dummyhead = new Node();
Node* tail = dummyhead;
while(la && lb ){
if(la->data < lb->data ){
tail->next = la;
tail = la;
la = la->next;
}else{
tail->next = lb;
tail = lb;
lb = lb->next;
}
}
if(la){
tail->next = la;
}
if(lb){
tail->next = lb;
}
return dummyhead;
}
int main(){
Node* List1head = creatlist();
Node* List2head = creatlist();
Node* ret = MergeList(List1head,List2head);
printfList(ret);
return 0;
}
程序运行结果:
最近开始复习前面的知识,没有时间刷leetcode的题目(想一道好费劲头秃),不过数据结构的作业都做完了还差一个大作业,作业是可以写的不过要翻书,感觉一些算法凭记忆记住好难555。上面两道题都是手打,其实题目很简单算法思路也很明白,不过全部自己打出来还是需要时间的,也可能是我太菜了.....TT 慢慢磨吧,继续推进!加油!