こんにちは、私はリンクリストのライブラリを作成しますが、このエラーと問題が発生します。私は何をすべきかわかりません。私は最初のtypedef struct listNodeをリストで変更し、listItemで2番目のlistNodeを置き換え、次にlinked_listsで置き換えます。listItemですべてのlistNodeが正常に動作しますが、リストの初期化関数を実装する必要があります。リストと項目数の頭を格納する別の構造体を作ってください。このエラーが発生した時点で私はこの時点で到着しました。 構造体データ型のリンクリストの問題
linked_lists.hコード:
#ifndef linked_lists_h
#define linked_lists_h
#include <stdio.h>
struct listNode;
typedef struct listNode{
int value;
struct list *next;
}listNode;
struct listaa{
int count;
listNode *head;
};
void deleteFirst(listNode *head);
void display(listNode *head);
void addInFront (listNode *head, int value);
void addLast (listNode *head, int value);
void deleteLast(listNode *head);
void add_at_poz(listNode *head, int value, int poz);
void insert_at_poz(listNode *head, int value, int poz);
void delete_at_poz(listNode *head, int poz);
void max(listNode *head);
void min(listNode *head);
#endif /* linked_lists_h */
linked_lists.cコード:私はここを参照してください
#include "linked_lists.h"
#include "stdlib.h"
// Single Linked Lists
void display(listNode *head) { // Display a linked list.
if(head->next != NULL){
listNode *current;
current = head;
while (current->next != NULL) {
current = current->next;
printf("%d, ", current->value);
}
} else {
printf("Lista este goala");
}
printf("\n");
}
//Adding value functions
// Adding in front of the list
void addInFront(listNode *head, int value) {
listNode *new_item;
new_item = (listNode *) malloc(sizeof(listNode));
new_item->next = head->next;
new_item->value = value;
head->next = new_item;
printf("Valoare %d a fost adaugata.\n", value);
}
// Adding at the end of the list
void addLast(listNode *head, int value) {
listNode *new_item,*current = head;
new_item = (listNode *) malloc(sizeof(listNode));
while(current->next != NULL)
current = current->next;
new_item->value = value;
new_item->next = NULL;
current->next = new_item;
}
// Adding a new item at specified pozition
void add_at_poz(listNode *head, int value, int poz) {
poz = poz - 1;
int iter = 0;
listNode *current = head, *new_item;
while(iter < poz) {
current = current->next;
iter++;
}
new_item = (listNode *)malloc(sizeof(listNode));
new_item = current->next;
current->next = new_item;
new_item->value = value;
}
// Insert a new item at specified pozition
void insert_at_poz(listNode *head, int value, int poz) {
poz = poz - 1;
int iter = 0;
listNode *current = head, *new_item;
while(iter < poz) {
current = current->next;
iter++;
}
new_item = (listNode *)malloc(sizeof(listNode));
new_item->next = current->next;
current->next = new_item;
new_item->value = value;
}
// Remove items from list
// Remove first item
void deleteFirst(listNode *head) {
listNode *deletedItem;
deletedItem = head->next;
printf("Elementul %d a fost sters din fata.\n", deletedItem->value);
head->next = deletedItem->next;
free(deletedItem);
}
// Delete last item
void deleteLast(listNode *head) {
listNode *deletedItem, *current;
current = head;
while(current->next->next != NULL)
current = current->next;
deletedItem = current->next;
printf("Ultimul elementul %d a fost sters\n",deletedItem->value);
current->next = NULL;
free(deletedItem);
}
void delete_at_poz(listNode *head,int poz) {
int iter = 0;
listNode *deletedItem, *current = head;
poz = poz - 1;
while(iter < poz) {
current = current->next;
iter++;
}
deletedItem = current->next;
current->next = deletedItem->next;
printf("Elementul de pe pozitia %d cu valoare %d a fost sters. \n", poz+1,deletedItem->value);
free(deletedItem);
}
void max(listNode *head) {
listNode *current;
int max = head->next->value;
current = head;
while (current->next != NULL) {
current=current->next;
if(current->value > max)
max = current->value;
}
printf("Maximul este %d.\n", max);
}
void min(listNode *head) {
listNode *current;
int min = head->next->value;
current = head;
while (current->next != NULL) {
current=current->next;
if(current->value < min)
min = current->value;
}
printf("Minimul este %d.\n", min);
}
'struct list'はどこに定義されていますか?あなたは 'struct listaa'を持っていますが、' struct list'はありません。 – kaylum