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

modify

上级 8f305a80
#ifndef SINGLELINKLIST_H_ #ifndef SINGLELINKLIST_H_
#define SINGLELINKLIST_H_ #define SINGLELINKLIST_H_
// //
// Include the C standard library header file here // Include the C standard library header file here
// //
#include <stdio.h> #include <stdio.h>
// //
// 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 Node { typedef struct Node
{
ElemType data; // Data fields ElemType data; // Data fields
struct Node* next; // pointer field struct Node* next; // pointer field
}LinkList; }LinkList;
...@@ -34,5 +30,4 @@ typedef struct Node { ...@@ -34,5 +30,4 @@ typedef struct Node {
int InsertBefore(LinkList* pListHead, int i, ElemType Elem); int InsertBefore(LinkList* pListHead, int i, ElemType Elem);
#endif /* SINGLELINKLIST_H_ */ #endif /* SINGLELINKLIST_H_ */
#include "SingleLinkList.h" #include "SingleLinkList.h"
#include <stdlib.h>
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
...@@ -17,7 +17,7 @@ int main(int argc, char* argv[]) ...@@ -17,7 +17,7 @@ int main(int argc, char* argv[])
// //
// Initializes the nodes of a single list // Initializes the nodes of a single list
// //
for(i=8; i>0; i--) for (i=8; i>0; i--)
{ {
pListNode = (LinkList*)malloc(sizeof(LinkList)); pListNode = (LinkList*)malloc(sizeof(LinkList));
pListNode->data = i; pListNode->data = i;
...@@ -33,7 +33,7 @@ int main(int argc, char* argv[]) ...@@ -33,7 +33,7 @@ int main(int argc, char* argv[])
InsertBefore(pListHead, 20, 15); // Invalid insert position. Insert failed. InsertBefore(pListHead, 20, 15); // Invalid insert position. Insert failed.
pListHeadTemp = pListHead; pListHeadTemp = pListHead;
while(pListHeadTemp->next != NULL) while (pListHeadTemp->next != NULL)
{ {
pListNode = pListHeadTemp->next; pListNode = pListHeadTemp->next;
printf("%d ", pListNode->data); printf("%d ", pListNode->data);
...@@ -44,7 +44,7 @@ int main(int argc, char* argv[]) ...@@ -44,7 +44,7 @@ int main(int argc, char* argv[])
// //
// Destroy single linked list // Destroy single linked list
// //
while(pListHead->next != NULL) while (pListHead->next != NULL)
{ {
pListNode = pListHead->next; pListNode = pListHead->next;
pListHead->next = pListNode->next; pListHead->next = pListNode->next;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论