📄 linkedlist.h
字号:
#include <stdio.h>
#include <stdlib.h>
//#include "MTS.h"
#ifndef NODE_H
#define NODE_H
typedef struct Node_t {
void* value; // Stored value
struct Node_t* pre; // previous node
struct Node_t* next; // next node
}Node;
typedef struct { // A testing struct as value in Node.
int i;
} A;
#endif
//typedef struct Node_t Node;
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
typedef struct {
Node* head; // First node
int length; // The current length of list
void (* destroyElement)(void*); // Destroy Function of stored element type
} LinkedList;
#endif
/**
* Create a LinkedList object. Note: If elements in the list don't need to be destroyed,
* please pass a dummy function.
* @param destroyElement Destroy Function of stored element type.
* @return Created LinkedList object
*/
LinkedList* createLinkedList(void (* destroyElement)(void*));
/**
* Destroy a LinkedList object
* @param list LinkedList object waiting for being destroyed
*/
void destroyLinkedList(void* list_);
/**
* Search in the list, if the return value of fun(theNode->value) is not 0, then return
* the node pointer for further operation, e.g. add, remove...
* If no value match the reqirement, return NULL.
* @param list LinkedList object being searched.
* @param fun Judging function
* @param funArg1 The first argument of fun(void*, void*)
* @return the node pointer, whose value makes fun() return a non-zero
*/
Node* search(LinkedList * list, int (*fun)(void*, void*), void* funArg1);
/**
* Return the value of specified node and remove the node from list.
* @param list LinkedList object being poped
* @param node The node being poped
* @return The value of poped node
*/
void* pop(LinkedList* list, Node* node);
/**
* Return the value of head node and remove the node from list.
* @param list LinkedList object being poped
* @return The value of poped node
*/
void* popHead(LinkedList* list);
/**
* Remove a specified node from the list.
* @param list LinkedList object whose node being removed
* @param node The being removed node
*/
void removeNode(LinkedList* list, Node* node);
/**
* Add a node created by specified value to the list before the specified node.
* @param list LinkedList object acts this action
* @param node add a new node before this node
* @param value The value of new node
* @return The newly created node
*/
Node * addBefore(LinkedList* list, Node* node, void* value);
/**
* Add a node created by specified value to the list after the specified node.
* @param list LinkedList object acts this action
* @param node add a new node after this node
* @param value The value of new node
* @return The newly created node
*/
Node* addAfter(LinkedList* list, Node* node, void* value);
/**
* Add a node created by specified value to the list as the head node.
* @param list LinkedList object acts this action
* @param node Added node as head node
* @param value The value of new node
* @return The newly created node
*/
Node* addAsHead(LinkedList* list, void* value);
/**
* Add a node created by specified value to tail of list
* @param list LinkedList object acts this action
* @param node Added node as tail node
* @param value The value of new node
* @return The newly created node
*/
Node * append(LinkedList* list, void* value);
/**
* Create a new node. Note: The function should olny be invocked by LinkedList
* @param value The value of the node.
* @param pre The previous node of this node
* @param next The next node of this node
* @return The newly created node
*/
Node* createNode(void* value, Node* pre, Node* next);
/**
* Destroy a node object.
* @param node Node object waiting to be destroyed
*/
void destroyNode(void* node_);
/**
* Print LinkedList object data feild.
* @param list the LinkedList object being printed
* @param printfun The 'printXXX' function for XXX element type
*/
void printLinkedList(LinkedList* list, void(*printfun)(void*));
/**
* Print Node object data feild.
* @param node the Node object being printed
* @param printfun The 'printXXX' function for XXX element type
*/
void printNode(Node* node, void(*printfun)(void*));
void printASendPack(void* a1);
void printAMessage(void * a1);
int compareSendPack(void* a_, void* a1_);
int compareMessage(void* a_, void* a1_);
void destroyA(void* a);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -