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

modify

上级 11bf2fa6
#ifndef DOUBLELINKLIST_H_
#define DOUBLELINKLIST_H_
//
// Include the C standard library header file here
//
#include <stdio.h>
//
// Other header files are included here
//
//
// Define the data structure here
//
typedef int ElemType; // The type of an element in a linked list
typedef struct DuLNode {
typedef struct DuLNode
{
ElemType data; // Data fields
struct DuLNode* prior; // Precursor pointer
struct DuLNode* next; // Subsequent pointer
......@@ -35,5 +31,4 @@ typedef struct DuLNode {
int InsertBefore(DuLinkList* pListHead, int i, ElemType Elem);
#endif /* DOUBLELINKLIST_H_ */
#include "DoubleLinkList.h"
#include <stdlib.h>
int main(int argc, char* argv[])
{
int i;
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* pListHeadTemp;
......@@ -18,7 +19,7 @@ int main(int argc, char* argv[])
//
// 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->data = i;
......@@ -33,11 +34,11 @@ int main(int argc, char* argv[])
// Insert a node before the ith node
//
InsertBefore(pListHead, 3, 88);
InsertBefore(pListHead, 20, 15); // Invalid insert position. Insert failed.
InsertBefore(pListHead, 20, 15); // Invalid insert position. Insert failed.
pListHeadTemp = pListHead;
pListNode = pListHeadTemp->next;
while(pListNode != pListHeadTemp)
while (pListNode != pListHeadTemp)
{
printf("%d ", pListNode->data);
pListNode = pListNode->next;
......@@ -47,7 +48,7 @@ int main(int argc, char* argv[])
//
// Destroy bidirectional circular linked list
//
while(pListHead->next != pListHead)
while (pListHead->next != pListHead)
{
pListNode = pListHead->next;
pListHead->next = pListNode->next;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论