هلاااااااااا
كيفكم ؟؟
إن شاء الله بخير
انا كتبت البرنامج كامل بس في خطأ واحد ماعرفت له :o
#include <iostream.h>
struct nodeType
{
int info;
nodeType *link;
};
//----------
class linkedList
{
private:
int count;
nodeType *first;
nodeType *last;
public:
linkedList();
void initializeList();
int length();
void destroy();
int front();
int back();
bool search(int);
void insertFirst(int);
void insertLast(int);
void deleteNode(int);
void print();
int splitAt( linkedList, int );
};
//----------------------------
// Constructor
linkedList::linkedList(){ first = NULL; last = NULL; count= 0; }
//--------------------------------------------------------------
// Destroy
void linkedList::destroy()
{
nodeType *temp;
while(first != NULL)
{
temp = first;
first = first->link;
delete temp;
}
last = NULL;
count =0;
}
//--------------------------------------------------------------
// Initialization
void linkedList::initializeList()
{
destroy();
}
//--------------------------------------------------------------
// Length
int linkedList::length()
{
return count;
}
//--------------------------------------------------------------
// Front
int linkedList::front()
{
return first->info;
}
//--------------------------------------------------------------
// Back
int linkedList::back()
{
return last->info;
}
//--------------------------------------------------------------
// Search
bool linkedList::search( int num)
{
nodeType *current;
bool found;
current = first;
found = false;
while(current != NULL && !found)
if(current->info == num)
found=true;
else
current = current->link;
return found;
}
//--------------------------------------------------------------
// Insert First
void linkedList::insertFirst(int num)
{
nodeType *newNode;
newNode = new nodeType;
newNode->info = num;
newNode->link = first;
first = newNode;
count++;
if(last == NULL)
last = newNode;
}
//---------------------------------------------------------------
// Delete Node
void linkedList::deleteNode(int num)
{
nodeType *current;
nodeType *trailCurrent;
bool found;
if(first==NULL)
cerr<<"Cannot delete from an empty list.\n";
else
{
if(first->info == num)
{
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 != num)
{
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;
}
}
}
//-------------------------------------------------------------------
// Insert Last
void linkedList::insertLast(int num)
{
nodeType *newNode;
newNode = new nodeType;
newNode->info = num;
newNode->link = NULL;
if(first == NULL)
{
first = newNode;
last = newNode;
count++;
}
else
{
last->link = newNode;
last = newNode;
count++;
}
}
//-------------------------------------------------------------------
// Print
void linkedList::print()
{
nodeType *current;
current = first;
while(current != NULL)
{
cout<<current->info<<" ";
current = current->link;
}
}
//----------------------------------------------------
// Split At
int linkedList::splitAt( linkedList* list, int num)
{
nodeType *current = list, *list1, *list2;
current = list;
for(int i=0; i<num; i++)
{
current = current->link;
}
list2 = current->link;
current->link = NULL
list2 =list;
}
//----------------------------------------------------
int main()
{
linkedList list;
linkedList list2;
list.insertFirst(1);
list.insertLast(5);
list.insertLast(7);
list.insertLast(3);
list.insertLast(6);
cout<<"The list is: ";
list.print();
cout<<endl;
list.print();
list.splitAt (list2, 7);
cout<<"The list after spliting is";
list.print();
cout<<"list 2 is:";
list2.print();
return 0;
}الخطأ هو
:\Documents and Settings\MoN MoN\Desktop\Assignment 3.cpp(239) : error C2511: 'splitAt' : overloaded member function 'int (class linkedList *,int)' not found in 'linkedList'
واهو يأشر على
[code]/ Split At
int linkedList::splitAt( linkedList* list, int num)
{
nodeType *current = list, *list1, *list2;
current = list;
for(int i=0; i<num; i++)
{
current = current->link;
}
list2 = current->link;
current->link = NULL
list2 =list;
}ارجو مساعدتكم :^)