📄 listofparts.cpp
字号:
#include "stdafx.h"
#include "ListOfParts.h"
//---------------------------------------------------------------------------
ListOfParts::ListOfParts()
: size(0), Head(NULL)
{
}
//---------------------------------------------------------------------------
int ListOfParts::Count()
{
return size;
}
//---------------------------------------------------------------------------
int ListOfParts::Add(CarPart *NewItem)
{
CarPart *Sample = new CarPart;
Sample = NewItem;
Sample->Next = Head;
Head = Sample;
return size++;
}
//---------------------------------------------------------------------------
CarPart *ListOfParts::Retrieve(int Position)
{
CarPart *Current = Head;
for(int i = 0; i < Position && Current != NULL; i++)
{
Current = Current->Next;
}
return Current;
}
//---------------------------------------------------------------------------
bool ListOfParts::Delete()
{
if( Head == NULL )
{
std::cout << "The list is empty\n";
return false;
}
else
{
CarPart *Current;
Current = Head->Next;
Head->Next = Current->Next;
size--;
return true;
}
}
//---------------------------------------------------------------------------
bool ListOfParts::Delete(int Position)
{
if( Retrieve(Position) == NULL )
return false;
else
{
Retrieve(Position - 1)->Next = Retrieve(Position+1);
size--;
return true;
}
}
//---------------------------------------------------------------------------
bool ListOfParts::Find(CarPart* ItemToFind)
{
CarPart *Current;
if( ItemToFind == NULL )
return false;
for(Current = Head; Current != NULL; Current = Current->Next)
{
if( (Current->PartNumber == ItemToFind->PartNumber) &&
(strcmp(Current->PartName, ItemToFind->PartName) == 0) &&
(Current->UnitPrice == ItemToFind->UnitPrice) )
return true;
else
Current->Next;
}
return false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -