神啊
来源:互联网 发布:手机淘宝怎么备注留言 编辑:程序博客网 时间:2024/06/06 19:27
我要慢慢研读~#ifndef LISTDEFINE_H_INCLUDED#define LISTDEFINE_H_INCLUDED#include "pubuse.h"template <typename T>class LinkList{public: struct node { T date; node* next; node* pre; };private: node* head; node* tail; int dire; int Size;public: LinkList() { head = CreatNode(); tail = CreatNode(); head->pre = NULL; head->next = tail; tail->next = NULL; tail->pre = head; dire = 1; Size = 0; } ~LinkList() { Clear(); free(head); free(tail); } node* CreatNode() { node* p = (node*)malloc(sizeof(node)); p->next = p->pre = NULL; return p; } int GetSize() { return Size; } T* GetFront() { if (dire) return GetTheFront(); else return GetTheBack(); } T* GetBack() { if (dire) return GetTheBack(); else return GetTheFront(); }private: T* GetTheFront() { return &(head->next->date); } T* GetTheBack() { return &(tail->pre->date); } Status InsertBack(const T& date) { node* p = CreatNode(); if (p == NULL) return ERROR; p->date = date; node* q = tail->pre; q->next = p; p->pre = q; p->next = tail; tail->pre = p; Size++; return OK; } Status InsertFront(const T& date) { node* p = CreatNode(); if (p == NULL) return ERROR; p->date = date; node* q = head->next; head->next = p; p->pre = head; p->next = q; q->pre = p; Size++; return OK; } Status InsertByIndexFront(const T& date, int index) { if (index > Size) return ERROR; if (index == Size) { InsertBack(date); return OK; } if (index == 0) { InsertFront(date); return OK; } node* New = CreatNode(); if (New == NULL) return ERROR; New->date = date; int cnt = 0; node* p = head->next; while (cnt < index) { p = p->next; cnt++; } node* q = p->pre; q->next = New; New->pre = q; p->pre = New; New->next = p; Size++; return OK; } Status InsertByIndexBack(const T& date, int index) { if (index > Size) return ERROR; if (index == Size) { InsertFront(date); return OK; } if (index == 0) { InsertBack(date); return OK; } node* New = CreatNode(); if (New == NULL) return ERROR; New->date = date; int cnt = 0; node* p = tail->pre; while (cnt < index) { p = p->pre; cnt++; } node* q = p->pre; p->next = New; New->pre = p; q->pre = New; New->next = q; Size++; return OK; } int FindByIndexFront(const T& date) { int cnt = 0; node* p = head->next; while (p != tail && p->date != date) { p = p->next; cnt++; } if (p == tail) return ERROR; return cnt; } int FindIndexBack(const T& date) { int cnt = 0; node* p = tail->pre; while (p != head && p->date != date) { p = p->pre; cnt++; } if (p == head) return ERROR; return cnt; } T FindByIndexFront(int index) { int cnt = 0; node* p = head->next; while (cnt < index) { p = p->next; cnt++; } return p->date; } T FindByIndexBack(int index) { int cnt = 0; node* p = tail->pre; while (cnt < index) { p = p->pre; cnt++; } return p->date; } T* GetPByIndexFront(int index) { int cnt = 0; node* p = head->next; while (cnt < 0) { cnt++; p = p->next; } return p; } T* GetPByIndexBack(int index) { int cnt = 0; node* p = tail->pre; while (cnt < 0) { cnt++; p = p->pre; } return p; } Status DeleteByIndexFront(int index) { if (Size <= index) return ERROR; int cnt = 0; node* p = head->next; while (cnt < index) { p = p->next; cnt++; } node* q = p->pre; q->next = p->next; p->next->pre = q; free(p); Size--; return OK; } Status DeleteByIndexBack(int index) { if (Size <= index) return ERROR; int cnt = 0; node* p = tail->pre; while (cnt < index) { p = p->pre; cnt++; } node* q = p->pre; q->next = p->next; p->next->pre = q; free(p); Size--; return OK; } void ShowFront(char c) { node* p = head->next; while (p != tail) { cout << p->date << c; p = p->next; } cout << endl; } void ShowBack(char c) { node* p = tail->pre; while (p != head) { cout << p->date << c; p = p->pre; } cout << endl; }public: Status InsertOnFront(const T& date) { if (dire) return InsertFront(date); else return InsertBack(date); } Status InsertOnBack(const T& date) { if (dire) return InsertBack(date); else return InsertFront(date); } Status InsertByIndex(const T& date, int index) { if (dire) return InsertByIndexFront(date, index); else return InsertByIndexBack(date, index); } bool Empty() { return Size == 0; } int FindByValue(const T& date) { if (dire) return FindByValueFront(date); else return FindByValueBack(date); } T FindByIndex(int index) { if (dire) return FindByIndexFront(index); else return FindByIndexBack(index); } T* GetPByIndex(int index) { if (dire) return GetPByIndexFront(index); else return GetPByIndexBack(index); } T* GetTail() { if (dire) return tail; else return head; } T* GetHead() { if (dire) return head; else return tail; } Status DeleteByValue(const T& date) { if (dire) return DeleteByValueFront(date); else return DeleteByValueBack(date); } Status DeleteByIndex(int index) { if (dire) return DeleteByIndexFront(index); else return DeleteByIndexBack(index); } Status Clear() { node* p = head->next; while (p != tail) { node* q = p->next; free(p); p = q; } Size = 0; return OK; } void Unique() { node* p = head->next; node* q = p->next; while (q != tail && q != NULL) { while (p->date == q->date) { q = q->next; free(p->next); p->next = q; q->pre = p; Size--; } p = q; q = q->next; } } void Reverse() { dire = !dire; } void Show(char c) { if (dire) ShowFront(c); else ShowBack(c); } LinkList& operator = (const LinkList& a) { if (!this->Empty()) this->Clear(); int cnt = 0; while (cnt < a.GetSize()) { this->InsertOnBack(a.GetPByIndex(cnt++)); } return *this; }};#endif // LISTDEFINE_H_INCLUDED
0 0
- 神啊!
- 神啊
- 神啊,赐个妞!!!
- 神啊!救救我吧!~~~
- 神啊,救救我吧~~~
- 神啊,救救我吧
- 神啊,救救我吧
- 神啊,救救我吧!
- 神啊 养好把
- 神啊,我好累,哈哈哈
- N多的职位,神啊~~~~~
- 神啊,请派个天使来救我吧
- 神啊,我是否还可获得救赎
- 神啊!替我砍掉那双手吧!
- 神啊,这是C嘛,这是helloworld嘛
- WAMP windows下建站,何乐而不为... PHP Apache MySql 神啊..
- 神啊,赶紧崩溃吧,再不崩溃,地球人都要混不下去了。
- 最小二乘法
- 2016 沈阳 大致题意
- READING NOTE: Speed/accuracy trade-offs for modern convolutional object detectors
- OSG环境实现Coons曲面的拼接绘制
- 爬虫时碰到的socket.error: [Errno 10060]错误的原因以及解决方法
- 神啊
- oracle组函数
- 一个关于宠物的小代码
- 一个简单的逆向
- OJ习题acm求数列的和
- CF_671B Robin Hood(二分)
- HDU 1008
- Web框架梳理:第二章:Hibernate入门、Hibernate关系映射和查询、hibernate注解开发
- linux查看防火墙状态及开启关闭命令