我倒,下面的程序怎么编译不了,大家编编,是不是我编译器累坏了
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct node
{
int data;
struct node *nextPtr;
}*LinkList, Lnode; /* 链表结构 */
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item);
static void Reverse(LinkList *headPtr);
static void Traverse(LinkList headPtr);
int main(void)
{
LinkList headPtr = NULL, tailPtr = NULL;
int item;
printf("Enter item (0 quit): ");
scanf("%d", &item);
while (item != 0) /* 输入0退出循环 */
{
CreateList(&headPtr, &tailPtr, item);
pintf("Enter item (0 quit): ");
scanf("%d", &item);
}
Traverse(headPtr);
if (headPtr != NULL) /* 链表不空对链表进行逆序 */
{
Reverse(&headPtr);
Traverse(headPtr);
}
else
{
printf("list is empty.\n");
}
#endif
getch();
return 0;
}
/* 创建单链表函数 */
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item)
{
LinkList newPtr;
if ((newPtr = (LinkList)malloc(sizeof(Lnode))) == NULL)
{
exit(1);
}
newPtr -> data = item;
newPtr -> nextPtr = NULL;
if (*headPtr == NULL)
{
newPtr -> nextPtr = *headPtr;
*headPtr = newPtr;
}
else
{
(*tailPtr) -> nextPtr = newPtr;
}
*tailPtr = newPtr;
}
/* 单链表逆转函数 */
static void Reverse(LinkList *headPtr)
{
LinkList previousPtr, currentPtr, tempPtr;
previousPtr = NULL;
currentPtr = *headPtr; /* currentPtr 指向头结点*/
while (currentPtr != NULL) /* 逆序单链表的循环 */
{
tempPtr = currentPtr -> nextPtr;
currentPtr -> nextPtr = previousPtr;
previousPtr = currentPtr;
currentPtr = tempPtr;
}
}
/* 打印链表函数 */
static void Traverse(LinkList headPtr)
{
while (headPtr != NULL)
{
printf("%d -> ", headPtr -> data);
headPtr = headPtr -> nextPtr;
}
printf("NULL\n");
}
----------------解决方案--------------------------------------------------------
我倒, 谢诸位捧场,搞定
----------------解决方案--------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct node
{
int data;
struct node *nextPtr;
}*LinkList, Lnode; /* 链表结构 */
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item);
static LinkList Reverse(LinkList headPtr);
static void Traverse(LinkList headPtr);
int main(void)
{
LinkList headPtr = NULL, tailPtr = NULL;
int item;
printf("Enter item (0 quit): ");
scanf("%d", &item);
while (item != 0)
{
CreateList(&headPtr, &tailPtr, item);
printf("Enter item: ");
scanf("%d", &item);
}
Traverse(headPtr);
if (headPtr != NULL)
{
headPtr = Reverse(headPtr);
Traverse(headPtr);
}
else
{
printf("list is empty.\n");
}
getch();
return 0;
}
/* 创建单链表函数 */
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item)
{
LinkList newPtr;
if ((newPtr = (LinkList)malloc(sizeof(Lnode))) == NULL)
{
printf("memory malloc failure.\n");
exit(1);
}
newPtr -> data = item;
newPtr -> nextPtr = NULL;
if (*headPtr == NULL)
{
newPtr -> nextPtr = *headPtr;
*headPtr = newPtr;
}
else
{
(*tailPtr) -> nextPtr = newPtr;
}
*tailPtr = newPtr;
}
/* 单链表逆转函数 */
static LinkList Reverse(LinkList headPtr)
{
LinkList previousPtr, currentPtr, tempPtr;
previousPtr = NULL;
currentPtr = headPtr; /* currentPtr 指向头结点*/
while (currentPtr != NULL) /* 逆序单链表的循环 */
{
tempPtr = currentPtr -> nextPtr;
currentPtr -> nextPtr = previousPtr;
previousPtr = currentPtr;
currentPtr = tempPtr;
}
return previousPtr;
}
/* 打印链表函数 */
static void Traverse(LinkList headPtr)
{
while (headPtr != NULL)
{
printf("%d -> ", headPtr -> data);
headPtr = headPtr -> nextPtr;
}
printf("NULL\n");
}
3----4楼发帖时间相差一分钟~~~~ 没赶上
----------------解决方案--------------------------------------------------------
稍微改了下 搞个双向多方便呀,非要。。。。。
[CODE]
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
int data;
struct node *nextPtr;
}*LinkList, Lnode;
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item);
static void Reverse(LinkList *headPtr);
static void Traverse(LinkList headPtr);
int main(void)
{
LinkList headPtr = NULL, tailPtr = NULL;
int item;
printf("Enter item (0 quit): ");
scanf("%d", &item);
while (item != 0)
{
CreateList(&headPtr, &tailPtr, item);
printf("Enter item (0 quit): ");
scanf("%d", &item);
}
Traverse(headPtr);
if (headPtr != NULL)
{
Reverse(&headPtr);
Traverse(headPtr);
}
else
{
printf("list is empty.\n");
}
return 0;
}
static void CreateList(LinkList *headPtr, LinkList *tailPtr, int item)
{
LinkList newPtr;
if ((newPtr = (LinkList)malloc(sizeof(Lnode))) == NULL)
exit(-1);
newPtr -> data = item;
newPtr -> nextPtr = NULL;
if (*headPtr == NULL)
{
newPtr -> nextPtr = *headPtr;
*headPtr = newPtr;
}
else
(*tailPtr) -> nextPtr = newPtr;
*tailPtr = newPtr;
}
static void Reverse(LinkList *headPtr)
{
LinkList previousPtr, currentPtr, tempPtr;
previousPtr = NULL;
currentPtr = *headPtr;
while (currentPtr != NULL)
{
tempPtr = currentPtr -> nextPtr;
currentPtr -> nextPtr = previousPtr;
previousPtr = currentPtr;
currentPtr = tempPtr;
}
*headPtr=previousPtr;
}
static void Traverse(LinkList headPtr)
{
while (headPtr != NULL)
{
printf("%d -> ", headPtr -> data);
headPtr = headPtr -> nextPtr;
}
printf("NULL\n");
}
[/CODE]
----------------解决方案--------------------------------------------------------
晕~慢了一步
----------------解决方案--------------------------------------------------------
个人感觉:你把那两函数定义为LinkList 型
返回一个值用起来方便,用&感觉别扭
----------------解决方案--------------------------------------------------------
返回我怕占用空间,传指针习惯了,
----------------解决方案--------------------------------------------------------
pintf("Enter item (0 quit): ");
我再倒,PRINTF我都能输错,你们用的C-FREE能检测出来吗,我的DEV怎么检测不出来
----------------解决方案--------------------------------------------------------
显然是可以检测出来的,再说了C―Free 中的函数名都是加亮的
如果名字是黑色,那显然是输入错了,而且编译器自己会报错
----------------解决方案--------------------------------------------------------
我一直以为我的DEV是最强的,看来不行了,我也要换代了
----------------解决方案--------------------------------------------------------