提交 e6cdb069 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 f84ac888
#ifndef DOUBLELINKLIST_H_ #ifndef DOUBLELINKLIST_H_
#define DOUBLELINKLIST_H_ #define DOUBLELINKLIST_H_
// //
// Include the C standard library header file here // Include the C standard library header file here
// //
...@@ -13,16 +12,14 @@ ...@@ -13,16 +12,14 @@
// Other header files are included here // Other header files are included here
// //
// //
// Define the data structure here // Define the data structure here
// //
typedef int ElemType; // The type of an element in a linked list typedef int ElemType; // The type of an element in a linked list
typedef struct DuLNode { typedef struct DuLNode
{
ElemType data; // Data fields ElemType data; // Data fields
struct DuLNode* prior; // Precursor pointer struct DuLNode* prior; // Precursor pointer
struct DuLNode* next; // Subsequent pointer struct DuLNode* next; // Subsequent pointer
......
#include "DoubleLinkList.h" #include "DoubleLinkList.h"
#include <stdlib.h>
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int i; int i;
ElemType Elem; ElemType Elem;
DuLinkList* pListHead; // A pointer to the head of a bidirectional circular list,Points to the header node // A pointer to the head of a bidirectional circular list,Points to the header node
DuLinkList* pListHead;
DuLinkList* pListNode; // Bidirectional circular list node pointer DuLinkList* pListNode; // Bidirectional circular list node pointer
DuLinkList* pListHeadTemp; DuLinkList* pListHeadTemp;
// //
...@@ -18,7 +19,7 @@ int main(int argc, char* argv[]) ...@@ -18,7 +19,7 @@ int main(int argc, char* argv[])
// //
// Initializes the nodes of a bidirectional circular list // Initializes the nodes of a bidirectional circular list
// //
for(i=8; i>0; i--) for (i=8; i>0; i--)
{ {
pListNode = (DuLinkList*)malloc(sizeof(DuLinkList)); pListNode = (DuLinkList*)malloc(sizeof(DuLinkList));
pListNode->data = i; pListNode->data = i;
...@@ -33,11 +34,11 @@ int main(int argc, char* argv[]) ...@@ -33,11 +34,11 @@ int main(int argc, char* argv[])
// Delete the ith node // Delete the ith node
// //
Delete(pListHead, 3, &Elem); Delete(pListHead, 3, &Elem);
Delete(pListHead, 20, &Elem); // Illegal deletion of location. Deletion failed. Delete(pListHead, 20, &Elem); // Illegal deletion of location. Deletion failed.
pListHeadTemp = pListHead; pListHeadTemp = pListHead;
pListNode = pListHeadTemp->next; pListNode = pListHeadTemp->next;
while(pListNode != pListHeadTemp) while (pListNode != pListHeadTemp)
{ {
printf("%d ", pListNode->data); printf("%d ", pListNode->data);
pListNode = pListNode->next; pListNode = pListNode->next;
...@@ -47,7 +48,7 @@ int main(int argc, char* argv[]) ...@@ -47,7 +48,7 @@ int main(int argc, char* argv[])
// //
// Destroy bidirectional circular linked list // Destroy bidirectional circular linked list
// //
while(pListHead->next != pListHead) while (pListHead->next != pListHead)
{ {
pListNode = pListHead->next; pListNode = pListHead->next;
pListHead->next = pListNode->next; pListHead->next = pListNode->next;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论