1.栈 栈顶在数组尾 栈顶在数组头
2.队列 循环队列 count=maxqueue;
front=0;
rear=maxqueue-1;
利用循环队列 可以很好的利用先前出队元素所剩下的空间
3.堆 extract-max O(logn)
T(n)=2(T(n/2))+O(n)
O(1)=1
insert O(h)=O(logn)
C~CN/2^(l-1)
l-1=logn
4.链表
1)node 包含结点值 和指针
2)插入
中间newPtr->next=prev->next;
prev->next=newPtr;
表头newPtr->next=head;
head=newPtr;
3)删除
中间prev->next=cur->next;
delete cur;
cur=NULL;
表头head=head->next
4)查找
for(prev=NULL,cur=head;cur!=NULL;cur=cur->next)
{if(cur->value==x)
return true;}
return false;
void print(ListNode * head){ if(head!=NULL){ if(head->value==x) cout<<head->value<<endl; else print(head->next); }
5递归
倒序输出链表的值
void find(ListNode * head) { {if(head->next==NULL) cout<<head->value<<endl; else{find(head->next); cout<<head->value<<endl; } }
https://www.cnblogs.com/kubidemanong/p/10538799.html
反转单链表
reverseLinkedList(ListNode * head) {if(head==NULL||head->next==NULL) return head; ListNode * newNode =reverseLinkedList(head->next); ListNode * t=head->next; t->next=head; head->next=NULL; return newList;}
两两交换链表中的结点
ListNode *swapPair(ListNode * head) {if(head==NULL||head->next==NULL) return head; ListNode * newNode=swapPair(head->next->next); ListNode * t= head->next->next; t->next=head->next; t->next->next=head; head->next=NULL; return newNode;}
原文:https://www.cnblogs.com/wwqdata/p/12110879.html