Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

i cannot compile the program. why?

#include <iostream>

using namespace std;

struct nodeType
{
int info;
nodeType *link;
};
class linkedListType {
public:
 void initializeList();
 bool isEmptyList() const;
 void print() const;
 int length() const;
 void destroyList();
 int front() const;
 int back() const;
 void insertFirst(const int& newItem) ;
 void deleteNode(const int& deleteItem);
 linkedListType();
 ~linkedListType();

 private:
 int count;
 nodeType *first;
 nodeType *last;
};
void linkedListType::insertFirst(const int& newItem)
{
    nodeType *newNode;
    newNode = new nodeType;
    assert(newNode!=NULL);
    newNode->info=newitem;
    newNode->link=first;
    first = newNode;
    count++;
    if (last==NULL)
    last==newNode;
}    
void linkedListType::deleteNode(const int& deleteItem)
{
nodeType *current;
nodeType *trailCurrent;
bool found;
if(first == NULL)
cerr<<"Cannot delete from an empty list.\n";
else
{
if(first->info == deleteItem)
{
current = first;
first = first->link;
count--;
if(first == NULL)
last = NULL;
delete current;
}
else
{
found = false;
trailCurrent = first;
current = first->link;
 while(current != NULL && !found)
{
 if(current->info != deleteItem)
{
trailCurrent = current;
current = current->link;
}
else
found = true;
}
if(found)
{
trailCurrent->link = current->link;
count--;
if(last == current)
last = trailCurrent;
delete current;
}
else
cout<<"Item to be deleted is not in the list." <<endl;
} //end else
} //end else
} //end deleteNode
void linkedListType::print() const
{
nodeType *current;
current=first;
while (current!=NULL)
{
    cout << current->info << " ";
    current=current->link;
}
}
bool linkedListType::isEmptyList() const
{
 return(first == NULL);
}
linkedListType::linkedListType()
{
 first = NULL;
 last = NULL;
 count = 0;
}
void linkedListType::destroyList()
{
 nodeType *temp;

 while (first != NULL)
 {
 temp = first;
 first = first->link;
 delete temp;
 }
 last = NULL;

 count = 0;
}
void linkedListType::initializeList()
{
destroyList();
}
int linkedListType::length() const
{
 return count;
}
int linkedListType::front() const
{
 assert(first != NULL);
 return first->info;
}
int linkedListType::back() const
{
 assert(last != NULL);
 return last->info;
}
linkedListType::~linkedListType()
{
 destroyList();
}
int main()
{
 int start=99;
 int data;
 linkedListType ListObj;
 ListObj.initializeList();
 ListObj.print();

 while (start !=0)
{
 cout << endl<<endl;
 cout << "Please select an option :.... " << endl<<endl;
 cout << "0. Exit the program." << endl;
 cout << "1. Insert First." << endl;
 cout << "2. Display Front." << endl;
 cout << "3. Display Last." << endl;
 cout << "4. Display All Nodes in the List." << endl;
 cout << "5. Delete Node." << endl;
 cout << "6. Delete All Nodes in the List." << " ";
 cout << " Choice: ";
 cin >> start;
 switch (start)
 {
 case 1 : cout << endl;
 cout << "Enter Int number: ";
cin >> data;
ListObj.insertFirst(data);
break;
 case 2 : cout << "---------------------" << endl;
 cout << "First Data: ";
cout << ListObj.front();
break;
 case 3 : cout << "---------------------" << endl;
 cout << "Last Data: ";
cout << ListObj.back();
break;
 case 4 : cout << "---------------------" << endl;
 ListObj.print();
break;
 case 5 : cout << "---------------------" << endl;
 cout << "Enter number to be deleted: ";
cin >> data;
ListObj.deleteNode(data);
break;
 case 6: ListObj.destroyList();
 default: cout << "Wrong....Please Reenter: ";
} //swtich
} //while
} //main()

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fundamentals of Input and Output Performance
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education