user-0 提问: 求助，线性表（顺序表）

回复:
user: user-1
content: 希望对你有帮助：https://blog.csdn.net/it_xiangqiang/category_10581430.html 希望对你有帮助：https://blog.csdn.net/it_xiangqiang/category_10768339.html

user: user-2
content: 链式实现  struct LinkNode{  int data;  LinkNode* next;  };  int InitLink_L(LinkNode*& L) {	//创建空链表  L = new LinkNode;  if (L == 0) return 0;  L->next = 0;  return 1;  }  int PushHead_LinkNode(LinkNode*& L, int x) {	//在链表头插入元素x  LinkNode* p = new LinkNode;  if (p == 0) return 0;  p->data = x;  p->next = L->next;  L->next = p;  return 1;  }  void PrintLink_L(LinkNode* L) {	//打印链表  LinkNode* p;  p = L->next;  while (p) {  cout << p->data;  p = p->next;  if (p) cout << ' ';  }  cout << endl;  }  void PopHead_LinkNode(LinkNode*& L) { //删除第一个结点  LinkNode* p;  if (L->next) {  p = L->next;  L->next = p->next;  delete p;  }  }  void Clear_LinkNode(LinkNode*& L) {	//清空链表元素，不包括头结点  while (L->next) {  PopHead_LinkNode(L);  }  }  void Free_LinkList(LinkNode*& L) {  while (L->next)	{  PopHead_LinkNode(L);  }  delete L;  L = 0;  }  int Length_LinkList(LinkNode* L) {	//计算单链表的长度  LinkNode* p;  p = L->next;  int len = 0;  while (p) {  len++;  p = p->next;  }  return len;  }  LinkNode* FindAddress_LinkList(LinkNode* L, int i) {	//查找单链表第i个结点并返回指针，否则返回空指针  if (i<1 || i>Length_LinkList(L)) return 0;  LinkNode* p;  p = L;  int j = 0;  while (j < i) {  p = p->next;  j++;  }  return p;  }  LinkNode* FindAddress_LinkList2(LinkNode* L, int i) {	//查找单链表第i个结点并返回指针，否则返回空指针  LinkNode* p;  int j = 1;  if (i <= 0)  return 0;  p = L;  while (1){  if (p == 0)  return 0;  if (i == j)  return p;  p = p->next;  j++;  }  }  void Insert_LinkNode(LinkNode*& L, int i, int x) {	//在第i个位置插入x,不包括链表尾部  if (i < 0 || i > Length_LinkList(L)) return;  LinkNode* p;  if (i == 1)  p = L;  else  p = FindAddress_LinkList2(L, i - 1);	//让p指向第i-1个元素  PushHead_LinkNode(p, x);	//将x插入以p为头结点的链表头部  }  void Insert_LinkNode2(LinkNode*& L, int i, int x) {	//在第i个位置插入x，包括链表尾部  if (i < 0 || i > Length_LinkList(L) + 1) return;  LinkNode* p;  if (i == Length_LinkList(L) + 1) {  LinkNode* q = new LinkNode;  q->data = x;  q->next = 0;  p = L->next;  while (p->next)  p = p->next;  p->next = q;  }  else {  if (i == 1)  p = L;  else  p = FindAddress_LinkList2(L, i - 1);	//让p指向第i-1个元素  PushHead_LinkNode(p, x);	//将x插入以p为头结点的链表头部  }  }  int DeleteLink_L(LinkNode*& L, int i) {	//删除第i个结点  if (i<0 || i>Length_LinkList(L)) return 0;  LinkNode* p;  if (i == 1)  p = L;  else  p = FindAddress_LinkList(L, i - 1);	//让p指向第i-1个元素  PopHead_LinkNode(p);	//将删除以p为头结点的链表头部  return 1;  }  LinkNode* Search_LinkList(LinkNode* L, int x) {	//在单链表中查找x若存在返回指针，否则返回空指针  LinkNode* p;  p = L->next;  while (p) {  if (p->data == x)  return p;  p = p->next;  }  return 0;  }  void UnionLinks(LinkNode* LA, LinkNode* LB, LinkNode*& LC) {	  //合并链表,合并后依然有序,原来的链表不再存在  LinkNode* a, * b, * c;  c = LC;  a = LA->next; delete LA; LA = 0;  b = LB->next; delete LB; LB = 0;  while (a && b) {  if (a->data <= b->data) {  c->next = a;  c = c->next;  a = a->next;  }  else {  c->next = b;  c = c->next;  b = b->next;  }  if (a) {  c->next = a;  }  if (b) {  c->next = b;  }  }  }  void Merge_LinkList(LinkNode*& LA, LinkNode*& LB, LinkNode*& LC) {	//合并链表,合并后依然有序,原来的链表不再存在  LinkNode* a, * b, * c;  c = LC;  a = LA->next; delete LA; LA = 0;  b = LB->next; delete LB; LB = 0;  while (a && b) {  if (a->data <= b->data) {  LA = a->next;  c->next = a;  a = LA;  c = c->next;  }  else {  LB = b->next;  c->next = b;  b = LB;  c = c->next;  }  }  if (a) {  c->next = a;  }  if (b) {  c->next = b;  }  }

user: user-2
content: 可能和你要求的函数不是完全一样，仅供参考  struct SqList {      int* elem;  int length;  int listsize;  };  int InitList_Sq(SqList &L) {	//构造空表  L.elem = 0;  L.length = 0;  L.listsize = 0;  return 1;  }  int InsertList_Sq(SqList &L, int i, int x) {	//在第i个位置插入x  if (L.listsize == 0) {  L.elem = new int[1];  L.listsize = 1;  }  if (i<0 || i>L.length) return 0;  if (L.length == L.listsize) {  int* newbase = new int[L.listsize * 2];  if (newbase == 0) return 0;  for (int j = 0; j < L.length; ++j) {  newbase[j] = L.elem[j];  }  delete L.elem;  L.elem = newbase;  L.listsize *= 2;  }  for (int j = L.length; j > i; --j) {  L.elem[j] = L.elem[j - 1];  }  L.elem[i] = x;  L.length++;  return 1;  }  int DeleteList_Sq(SqList& L, int i, int& x) { //删除第i个元素并用x返回删除的元素  if (i<0 || i>L.length - 1) return 0;  x = L.elem[i];  for (int j = i; j < L.length - 1; ++j) {  L.elem[j] = L.elem[j + 1];  }  L.length--;  return 1;  }  int DeleteList_Sq(SqList& L, int i) {	//重载删除第i个元素不返回元素内容  if (i<0 || i>L.length - 1) return 0;  for (int j = i; j < L.length - 1; ++j) {  L.elem[j] = L.elem[j + 1];  }  L.length--;  return 1;  }  void PrintList_Sq(SqList L) {	//打印顺序表  for (int i = 0; i < L.length; ++i) {  if (i) cout << ' ';  cout << L.elem[i];  }  cout << endl;  }  int FindElem(SqList L, int x) {	//	查找x返回下标  int i;  for (i = 0; i < L.length - 1; ++i) {  if (x == L.elem[i]) return i;  }  return -1;  }  void UnionLists_Sq(SqList A, SqList B, SqList &C) {	//合并两个有序表，并使其合并后依然有序  int i = 0, j = 0,k = 0, m = A.length, n = B.length;  while (i < m && j < n) {  if (A.elem[i] <= B.elem[j]) {  InsertList_Sq(C, k++, A.elem[i++]);  }  else {  InsertList_Sq(C, k++, B.elem[j++]);  }  }  if (j == n) {  while (i < m) {  InsertList_Sq(C, k++, A.elem[i++]);  }  }  if (i == m) {  while (j < n) {  InsertList_Sq(C, k++, B.elem[j++]);  }  }  }  void UnionLists2(SqList &A, SqList B) {	// 将在B中不在A中的元素插入到A中  int i;  for (i = 0; i < B.length; ++i) {  if (FindElem(A, B.elem[i]) == -1) {  InsertList_Sq(A, A.length, B.elem[i]);  }  }  /*  int i, j;  for (j = 0; j < B.length; ++j) {  for (i = 0; i < A.length; ++i) {  if (A.elem[i] == B.elem[i]) break;  else {  InsertList_Sq(A,A.length, B.elem[j]);  break;  }  }  }  */  }  void DeleteElem(SqList& L) {	//删除重复元素  for (int i = 0; i < L.length; ++i) {  for (int j = i + 1; j < L.length; ++j) {  if (L.elem[i] == L.elem[j]) {  DeleteList_Sq(L, j);  j--;  }  }  }  }

user: user-3
content: 先自己写写，遇到问题把代码和问题描述清楚发出来吧～