雙向鍊錶 基本操作

2021-07-12 07:23:37 字數 3062 閱讀 6403

"test.c"

#define _crt_secure_no_warnings 1

#include "doubleslishtnode.h"

void test1()//initdslist pushback printfdslist popback

void test2()//pushfront popfront

void test3()//find erase

int main()

"doubleslistnode.h"

#ifndef __doubleslistnode_h__

#define __doubleslistnode_h__

#pragma once;

#include #include #include typedef int datatype;

typedef struct doubleslistnode

doubleslistnode,*pdoubleslistnode;

//初始化雙向鍊錶

void initdslist(pdoubleslistnode* phead);

//列印雙向鍊錶

void printfdslist(pdoubleslistnode* phead);

//開闢結點記憶體

pdoubleslistnode byenode(datatype data);

//尾插法

void pushback(pdoubleslistnode* phead,datatype data);

//尾刪法

void popback(pdoubleslistnode* phead);

//頭插法

void pushfront(pdoubleslistnode* phead,datatype data);

//頭刪法

void popfront(pdoubleslistnode* phead);

//在雙向鍊錶中查詢乙個元素

pdoubleslistnode find(pdoubleslistnode* phead,datatype x);

//刪除pos位置上的結點

void erase(pdoubleslistnode* phead,pdoubleslistnode pos);

//在雙向鍊錶的pos位置插入x

void insert(pdoubleslistnode* phead,pdoubleslistnode pos,datatype x);

#endif//__doubleslistnode_h__

"doubleslistnode.c"

#define _crt_secure_no_warnings 1

#include "doubleslishtnode.h"

void initdslist(pdoubleslistnode* phead)

pdoubleslistnode byenode(datatype data)

else

return pnewnode;

}void printfdslist(pdoubleslistnode* phead)

pnode = *phead;

while (null !=pnode)

printf("\n");

}void pushback(pdoubleslistnode* phead,datatype data)

else

pnewnode = byenode(data);

pnewnode->_rightnode = null;

pnewnode->_leftnode = pnode;

pnode->_rightnode = pnewnode; }}

void popback(pdoubleslistnode* phead)

else if ((*phead)->_rightnode == null)

else

pcurnode = ppurnode;

ppurnode->_leftnode->_rightnode = null;

free(pcurnode);

pcurnode = null; }}

void pushfront(pdoubleslistnode* phead,datatype data)

else }

void popfront(pdoubleslistnode* phead)

//if ((*phead)->_rightnode = null)

// else

else

}}pdoubleslistnode find(pdoubleslistnode* phead,datatype x)

pnode = *phead;

while (null !=pnode)

else

}return null;

}void erase(pdoubleslistnode* phead,pdoubleslistnode pos)

else

else

}}//還沒屢清楚,等我弄明白了後面再補上

//void insert(pdoubleslistnode* phead,pdoubleslistnode pos,datatype x)

// //

// pnode = *phead;

// while (null != pnode)

//

// else

//

// }

// else

//

// }

//}

雙向鍊錶基本操作

帶頭節點的雙向鍊錶操作 include include include define ok 1 define error 0 define overflow 0 using namespace std typedef int status typedef int elemtype typedef s...

雙向鍊錶基本操作

package com.bei.linkedlist auther honeysky date 2020 11 10 13 38 public class doublelinkedlistdemo 建立乙個雙向鍊錶的類 class doublelinkedlist 遍歷雙向鍊錶的方法 public ...

雙向鍊錶的基本操作

雙向鍊錶的第個結點有兩個指標,分別指向其直接前驅結點和直接後驅結點。這樣就可以從表中任意的元素結點出發,從兩個方向遍歷鍊錶。typedef struct node node node createdll bytail 尾插法構造帶頭結點的雙向鍊錶 r next null return head 結尾...