#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;
//用线性表合并两个有序表
enum myerrorcode{ rangeerror,success,overflow,underflow};
template<class T>
struct node
{
T data;
node* next;
};
template<class T>
class list
{
public:
node<T>* head;
int count;
list()
{
head = new node<T>;
head->next = NULL;
count =0;
}
int length()
{
return count;
}
myerrorcode getelement(int i, T& x)
{
node<T>* p = new node<T>;
p = head->next;
int j = 1;
while (p!=NULL&&j!=i)
{
p = p->next;
j++;
}
if (p == NULL)
return rangeerror;
else
{
x = p->data;
return success;
}
}
node<T>* locate(T x)
{
node<T>* p = new node<T>;
p = head->next;
while (p != NULL)
{
if (p->data == x)
return p;
else
p = p->next;
}
return NULL;
设计算法将递增有序线性表A/B的元素值合并为另一个递增有序的表C
最新推荐文章于 2023-05-20 22:14:47 发布
本文探讨如何使用C++设计算法,将两个递增有序的线性表A和B的元素值有效合并到一个新的递增有序列表C中,保证合并后的顺序依然递增。
摘要由CSDN通过智能技术生成