#include <stdio.h> #include <string.h> #include <stdlib.h> #define LIST_INIT_SIZE 100 #define LIST_INCREMENT 10 int *p, *q; typedef struct{ int *elem; //基地址类型怎么写也就是这个线性表中存储的数据的类型 int length; int listsize; }SqList; bool InitList_Sq(SqList &L)//创建线性表的时候函数返回类型可以表示这个线性表是否创建成功 { L.elem = (int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!l.elem)exit(OVERFLOW);//存储分配失败,但OVERFLOW?????是什么???????????????????????????? L.length = 0; L.listsize = LIST_INIT_SIZE; return 1; } bool ListInsert_Sq(SqList &L, int i, int e){ if(i < 1 || i > L.length + 1) return 0; // 等于L.length+1不是也应该报错吗?????????????? if(L.length >= L.listsize){ int *newbase = (int *)realloc(L.elem, (L.listsize + LIST_INCREMENT)*sizeof(int)); if(!newbase) exit(OVERFLOW); //OVERFLOW?????????????????? L.elem = newbase; L.listsize += LIST_INCREMENT; } q = &(L.elem[i-1]); for(p = &(L.elem[L.length-1]); p >= q; --p) *p+1 = *p; *q = e; ++L.length; return 1; } bool ListDelete_Sq(SqList &L, int i, int &e) { if((i < 1)||(i > L.length)) return 0; p = &(L.elem[i-1]); } void main() {}
冒泡,快排,归并排序,sort排序,sort(a, a+n),sort(a, a+n, cmp); 二分查找,栈(top指针)(str提供有栈的操作),队列(pre和last指针),链表,