有没有大佬在的,我这双向链表怎么没办法遍历
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma warning(disable:4996)
#define num 30
typedef struct king
{
char mv_name[num];//电影名
int number;//电影序号
struct king* head;//保存上一个节点的地址
struct king* next;//保存下一个节点的地址
}new;
char* _scanf(char* fp, int a);
void _printf(new* fp1, new* fp2);
int main()
{
char input[num];
new* head = NULL; new* p1 = NULL; new* p2 = NULL;//head头指针 p1=节点分配内存 p3=链接作用
puts("stdin mv the name");
while (_scanf(input, num) != NULL && input[0] != '\0')
{
p1 = (new*)malloc(sizeof(new));
if (!p1) break;
if (head == NULL)
{
head = p1;
head->head = NULL;
}
else
{
p2->next = p1;//第一个节点的next保存下一个节点的地址
p1->head = p2;//下一个节点保存上一个节点的地址
}
p1->next = NULL;
strcpy(p1->mv_name, input);
puts("stdin 0-9");
scanf_s("%d", &p1->number);
while (getchar() != '\n') continue;
puts("stdin mv the name");
p2 = p1;
}
p1 = head;
_printf(p1,p2);
return 0;
}
void _printf(new* fp1, new* fp2
{
while(fp1->null)
{
printf("%s %d",fp1->mv_name,fp1->nuber);
fp1=fp1->next;
}
while(fp2->null)
{
printf("%s %d",fp2->mv_name,fp2->nuber);
fp2=fp2->head;
}
}
char* _scanf(char* fp, int a)
{
char* fp1 = NULL;
char* fp2 = NULL;
fp1 = fgets(fp, a, stdin);
if (fp1)
{
fp2 = strchr(fp, '\n');
if (fp2)
*fp2 = '\0';
else
while (getchar() != '\n')
continue;
}
return fp1;
}
#include<stdlib.h>
#include<string.h>
#pragma warning(disable:4996)
#define num 30
typedef struct king
{
char mv_name[num];//电影名
int number;//电影序号
struct king* head;//保存上一个节点的地址
struct king* next;//保存下一个节点的地址
}new;
char* _scanf(char* fp, int a);
void _printf(new* fp1, new* fp2);
int main()
{
char input[num];
new* head = NULL; new* p1 = NULL; new* p2 = NULL;//head头指针 p1=节点分配内存 p3=链接作用
puts("stdin mv the name");
while (_scanf(input, num) != NULL && input[0] != '\0')
{
p1 = (new*)malloc(sizeof(new));
if (!p1) break;
if (head == NULL)
{
head = p1;
head->head = NULL;
}
else
{
p2->next = p1;//第一个节点的next保存下一个节点的地址
p1->head = p2;//下一个节点保存上一个节点的地址
}
p1->next = NULL;
strcpy(p1->mv_name, input);
puts("stdin 0-9");
scanf_s("%d", &p1->number);
while (getchar() != '\n') continue;
puts("stdin mv the name");
p2 = p1;
}
p1 = head;
_printf(p1,p2);
return 0;
}
void _printf(new* fp1, new* fp2
{
while(fp1->null)
{
printf("%s %d",fp1->mv_name,fp1->nuber);
fp1=fp1->next;
}
while(fp2->null)
{
printf("%s %d",fp2->mv_name,fp2->nuber);
fp2=fp2->head;
}
}
char* _scanf(char* fp, int a)
{
char* fp1 = NULL;
char* fp2 = NULL;
fp1 = fgets(fp, a, stdin);
if (fp1)
{
fp2 = strchr(fp, '\n');
if (fp2)
*fp2 = '\0';
else
while (getchar() != '\n')
continue;
}
return fp1;
}
思路应该没错吧