Я пытаюсь создать программу для связанного списка. Я хочу создать оператор case, где пользователь может выбрать 1. добавить узел 2. удалить узел 3. искать узел 4. отобразить связанный список (5 узлов в строке) 5. выйти из программыСоздание связанного списка - ошибки компилятора
Однако программа все еще находится в процессе разработки, и я не могу ее скомпилировать до сих пор. Я пытаюсь найти то, что заставляет его не компилироваться. кажется, моя основная программа не свяжет файл заголовка. любые предложения, пока я не могу скомпилировать или ссылку? Я хочу, чтобы ошибки были разработаны до того, как я продолжу работу над основным. И где лучше всего создать мою структуру?
Ошибки от кровопролития Dev C++
list.cpp: In constructor list::list():
list.cpp:7: error: node undeclared (first use this function)
list.cpp:7: error: (Each undeclared identifier is reported only once for each function it appears in.)
list.cpp:7: error: head undeclared (first use this function)
list.cpp:8: error: precurrent undeclared (first use this function)
list.cpp:9: error: current undeclared (first use this function)
list.cpp: At global scope:
list.cpp:16: error: expected constructor, destructor, or type conversion before :: token
list.cpp:16: error: expected , or ; before :: token
list.cpp: In member function void list::insert(int):
list.cpp:24: error: head undeclared (first use this function)
list.cpp:24: error: null undeclared (first use this function)
list.cpp:24: error: stray \ in program
list.cpp:24: error: stray \ in program
list.cpp:24: error: If undeclared (first use this function)
main.cpp
#include <string>
#include <iostream>
using namespace std;
#include <cstdlib>
#include "list.h"
using namespace std;
int main(int argc, char *argv[])
{
list* list1;
system("PAUSE");
return EXIT_SUCCESS;
}
Link.cpp
#include <iostream>
using namespace std;
#include "list.h"
list::list()
{
node *head = NULL;
node *precurrent = NULL;
node *current = NULL;
int *temp = 0;
int _insert = 0;
int _search = 0;
int _remove = 0;
}
List::~list()
{
while (head != 0)
remove();
}
void list::insert(int _insert)
{
if (head==null) \\If there is no list already, create a new head.
{
temp = new Node;
temp->data = _insert;
head = temp;
}
else \\otherwise, insert the new node after current
{
temp = new Node;
temp->data = _insert;
temp->next = current->next;
current->next = temp;
}
}
void list::search(int _search)
{
current=head;
while (head->next != 0) //Cycle through the list, and if the number is found, say so
{
if (current->data = _search)
cout<<"Number found."<<endl;
else
cout<<"Number not found."<<endl;
}
}
void list::remove(int _remove)
{
if (head == null)
cout <<"Error. No list."<<endl;
else if (head->next == null)
{
num = head->data;
delete head;
head=null;
current=null;
}
else if (head == current)
{
temp = head->next;
num = head->data;
delete head;
head=temp;
current=temp;
}
else
{
temp = current->next;
num = current->data;
delete current;
precurrent->next = temp;
current = temp;
}
}
ostream &operator<<(ostream& osObject, list& list){
nodeType<Type>* current = list.head;
int i = 0;
while (current != NULL) //while more data to print
{
osObject << current->info << " ";
current = current->link;
++i;
if (i % 5 == 0)
{
cout << '\n';
i = 0;
}
}
osObject << '\n'; // print the ending newline
return osObject;
}
Link.h
//CLASS PROVIDED: list
//
// CONSTRUCTOR for the list class:
// list()
// Description: Constructor will initialize variables
// Preconditions: None
// Postcondition: int insert = ""
// int search = ""
// int remove = ""
// ~list()
// Description: Destructor destroys variables
// Preconditions: None
// Postcondition: variable deleted
//
// MEMBER FUNCTIONS for the list class
//
// string insert(int)
// Description: Inserts an integer into a linked list
// Precondition: none
// Postcondition: function returns Success/Error message.
//
// string search(int);
// Description: Searches for certain linked list member and returns int to set current variable
// Precondition: none
// Postcondition: function returns int
//
// string remove(int);
// Description: removes linked list member
// Precondition: user sends int to be deleted
// Postcondition: function returned string sddress
//
// void display(void);
// Description: displays entire linked list
// Precondition: none
// Postcondition: function returns screen output
//
// void quit(void);
// Description: closes program
// Precondition: none
// Postcondition: none
//
#ifndef LIST_H
#define LIST_H
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
class list
{
friend ostream& operator<< (ostream &os, const list&);
public:
//CONSTRUCTOR/DESTRUCTOR---------------------
list();
~list();
//GETS---------------------------------------
void insert(int);
string search(int);
string remove(int);
void display(void);
void quit(void);
private:
int insert;
int search;
int remove;
};
#endif
Что такое '# inclide'? – Drahakar
Нам нужна ошибка компиляции. – Drahakar
И обычный подход состоит в том, чтобы напечатать несколько десятков строк кода, скомпилировать их (и исправить их до их компиляции) и повторить. –