/*
* DLList.h
*
* Created on: Oct 6, 2015
* Author: chris
*/
#ifndef DLLIST_H_
#define DLLIST_H_
typedef int ElemType;
typedef struct DLNode{
ElemType data;
DLNode* prior;
DLNode* next;
}*DLList;
bool DLListCreate(DLList& DLL);
void DLListDestroy(DLList& DLL);
void DLListClear(DLList DLL);
int DLListLength(DLList DLL);
bool DLListEmpty(DLList DLL);
bool DLListInsert(DLList DLL, int pos, ElemType e);
bool DLListDelete(DLList DLL, int pos, ElemType& e);
bool DLListAppend(DLList DLL, ElemType e);
int DLListFindElem(DLList DLL, ElemType e);
bool DLListGetElem(DLList DLL, int pos, ElemType& e);
void DLListDisplay(DLList DLL);
void DLListSort(DLList DLL, bool desc);
#endif /* DLLIST_H_ */
/*
* DLList.cpp
*
* Created on: Oct 6, 2015
* Author: chris
*/
#include"DLList.h"
#include<iostream>
#include<cstdlib>
using namespace std;
bool DLListCreate(DLList& DLL)
{
DLL = new DLNode;
if(!DLL) return false;
DLL->prior = DLL->next = NULL;
return true;
}
void DLListDestroy(DLList& DLL)
{
DLNode * pcur;
while(DLL) {
pcur = DLL;
DLL = DLL->next;
delete pcur;
}
}
void DLListClear(DLList DLL)
{
DLList sub = DLL->next;
DLL->next = NULL;
DLNode *pcur;
while(sub) {
pcur = sub;
sub = sub->next;
delete pcur;
}
}
int DLListLength(DLList DLL)
{
DLNode * pcur = DLL->next;
int cnt = 0;
while(pcur) {
++cnt;
pcur = pcur->next;
}
return cnt;
}
bool DLListEmpty(DLList DLL)
{
return DLL->next == NULL;
}
bool DLListInsert(DLList DLL, int pos, E