10 2013 档案
摘要:int Partition(int*list,int i,int j){ int pivot=list[i];//1 //2 while (i=pivot) j--; if(i<j) list[i++]=list[j]; while (i<j&&list[i]<=pivot) i++; list[j--]=list[i]; } //3 list[i]=pivot; return i;}void QuickSort(int* list, int l...
阅读全文
摘要://不包含头结点typedef struct LNode{ int data; LNode* next;}LNode,*LinkList;LinkList reverse(LinkList head){ if(head==nullptr||head->next==nullptr)//头结点检测; return head; LinkList cur=nullptr; LinkList pre=nullptr; LinkList next=nullptr; //初始化指针 pre=head; cur=pre->next; ...
阅读全文
摘要:#include //非malloc#include typedef struct LNode{ int data; LNode* next; }LNode,*Linklist;void josephus(int n,int k,int m){ Linklist cur,head,prior,temp; head=(Linklist)malloc(sizeof(LNode)); head->data=1; head->next=head; cur=head;//当前节点设为头结点 for (int i=2; idata=i...
阅读全文
摘要://双栈实现队列//入栈:直接在栈A中入栈。//出栈:(1)如果栈B非空,栈B直接出栈;(2)如果栈B为空,将栈A中元素转移到栈B中,再由栈B出栈;#include using namespace std;templatestruct Myqueue{ stack s1; stack s2; void push(T &t) { s1.push(t); } void pop() { if(s2.empty()) { while(!s1.empty()) ...
阅读全文
摘要:1 //存储空间大小宏定义 2 #define STACK_INIT_SIZE 100 3 #define STACKINCREMENT 10 4 5 //结构体定义 6 typedef struct{ 7 SElemType * base; 8 SElemType * top; 9 int StackSize;10 }SqStack;11 12 //方法声明13 status InitStack(SqStack &s);14 status Push(SqStack &s,SElemType e);15 status Pop(Sqstack &s,...
阅读全文

浙公网安备 33010602011771号