Em đang làm phần danh sách liên kêt. Các bác xem hộ em là phần tham số chuyền vào hàm push, input vs init của em đúng chưa ạ. Em thử xuất ra màn hình head.data nhưng hình như nó chưa được gán. Em đoán là do phần tham số chuyền vào của push vs input và init bị lỗi.
Đây là phần code ạ:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct Node {
int data;
Node *next;
Node *priv;
};
void init(Node *head)
{
head = NULL;
}
int isEmpty(Node *head)
{
if (head == NULL) return 1;
else return 0;
}
Node *creat(int x)
{
Node *n = (Node*)malloc(sizeof(Node));
n->next = NULL;
n->priv = NULL;
n->data = x;
return n;
}
void push(Node *head, int x)
{
Node *p = creat(x);
if (isEmpty(head)==1)
{
head = creat(x);
}
else
{
head->priv = p;
p->next = head;
p->priv = NULL;
head = p;
}
}
void input(Node *head, FILE *f)
{
int x;
Node *p = head;
if (f != NULL)
{
while (!feof(f))
{
fscanf(f, "%d", &x);
push(p, x);
printf("%d", x);
}
printf("\nda input xong");
fclose(f);
}
}
void output(Node *head)
{
Node *p = head;
printf("danh sach lk");
while (p != NULL)
{
printf("%d", p->data);
p = p->next;
}
}
void main()
{
Node head;
FILE *f;
f = fopen("D:\\ftest.txt", "rt");
init(&head);
push(&head, 2);
push(&head, 3);
push(&head, 4);
printf("%d", head.data);
//output(&head);
_getch();
}
Em sợ mọi người khó đọc nên post thêm hình.




83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?