/**+===========================================================================
File: listType.cpp
Description:
Sort some int or float
Functions:
CListType
Constructor
~CListType
Destructor
IsEmpty
examine if the container is empty
IsFul
examine if the container is full
Sort
sort these inputted data
Print
display the numbers after sorting
InsertAt
insert the numbers into the container
Author:
Penny Pan Jul-15-2008
Revision:
Jul-15-2008 Penny Pan Initialize
Jul-15-2008 Penny Pan Modification
Check the coding style
Jul-15-2008 Penny Pan Modification
Check the coding style
Jul-17-2008 Penny Pan Modification
Check the coding style
Jul-17-2008 Penny Pan Modification
Check the coding style
-------------------------------------------------------------------------------
** SPREADCOMM CONFIDENTIAL
** Copyright(C) 2008 Spreadcomm Technology Corp. All Rights Reserved.
**
** The source code contained or described herein and all documents related
** to the source code (Material) are owned by Spreadcomm Technology Corp.
** The Material is protected by worldwide copyright and trade secret laws and
** treaty provisions. No part of the Material may be used, copied, reproduced,
** modified, published, uploaded, posted, transmitted, distributed, or disclosed
** in any way without Spreadcomm prior express written permission.
============================================================================+*/
#include <iostream>
#include <windows.h>
#include "listType.h"
#include "debug.h"
using namespace std;
#define MAX_NUM 5
#define LIST_SIZE 100
#define ONE 1
#define SPACE " "
#define ENTERINT "Enter five integer: "
#define SORT "After sorting,the list is: "
#define ENTERFILOAT "Enter five float numbers: "
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - Constructor
Arguments:
m_iListSize
Initialize the function
Modifies:
None
Returns:
None
Description:
Constructor of CListType
-----------------------------------------------------------------------------*/
template<class ElemType>
CListType<ElemType>::CListType(int m_iListSize)
{
DBG_MSG(MSG_INFO, L"+CListType");
m_iMaxSize = m_iListSize;
m_iLength = 0;
m_pList = new ElemType[m_iMaxSize];
assert(m_pList != NULL);
DBG_MSG(MSG_INFO, L"-CListType");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - Destructor
Arguments:
None
Modifies:
m_pList
delete the memory of the container
Returns:
None
Description:
DEstructor of CListType
-----------------------------------------------------------------------------*/
template<class ElemType>
CListType<ElemType>::~CListType()
{
DBG_MSG(MSG_INFO, L"+ ~CListType");
delete [] m_pList;
DBG_MSG(MSG_INFO, L"- ~CListType");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - IsEmpty
Arguments:
Void
Modifies:
None
Returns:
BOOL:
TRUE: Stand for the container is empty
FALSE:stand for the container is not empty
Description:
Examine if the container is empty
-----------------------------------------------------------------------------*/
template<class ElemType>
bool CListType<ElemType>::IsEmpty() const
{
DBG_MSG(MSG_INFO, L"+ IsEmpty");
if (m_iLength == 0)
{
return true;
}
else
{
return false;
}
DBG_MSG(MSG_INFO, L"- IsEmpty");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - IsFull
Arguments:
Void
Modifies:
None
Returns:
BOOL:
TRUE: Stand for the container is full
FALSE:stand for the container is not full
Description:
Examine if the container is full
-----------------------------------------------------------------------------*/
template<class ElemType>
bool CListType<ElemType>::IsFull() const
{
DBG_MSG(MSG_INFO, L"+ IsFull");
if (m_iLength == m_iMaxSize)
{
return true;
}
else
{
return false;
}
DBG_MSG(MSG_INFO, L"- IsFull");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - Sort
Arguments:
m_pList
m_iLength
Modifies:
m_pList
modify after every time sorting
Returns:
None
Description:
sort these inputted numbers
-----------------------------------------------------------------------------*/
template<class ElemType>
void CListType<ElemType>::Sort()
{
DBG_MSG(MSG_INFO, L"+ Sort");
int iMin; //The time of each loop in sort
int iNum; //The sub-time of each loop in sort
ElemType temp; //The temporary number store temporary number
for (iMin = 0; iMin < m_iLength - ONE; iMin++)
{
for (iNum = 0; iNum < m_iLength - ONE - iMin; iNum++)
{
if (m_pList[iNum] > m_pList[iNum + ONE])
{
temp = m_pList[iNum];
m_pList[iNum] = m_pList[iNum + ONE];
m_pList[iNum + ONE] = temp;
}
}
}
DBG_MSG(MSG_INFO, L"- Sort");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - Print
Arguments:
m_iLength
m_pList
Modifies:
None
Returns:
None
Description:
display the numbers after sorting
-----------------------------------------------------------------------------*/
template<class ElemType>
void CListType<ElemType>::Print() const
{
DBG_MSG(MSG_INFO, L"+ Print");
for (int i = 0; i < m_iLength; ++i)
{
cout << m_pList[i] << SPACE;
cout << endl;
}
DBG_MSG(MSG_INFO, L"- Print");
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CListType::CListType - InsertAt
Arguments:
item
m_iPosition
Modifies:
m_iLength
modify the value after every operation
Returns:
None
Description:
insert the numbers into the container
-----------------------------------------------------------------------------*/
template<class ElemType>
void CListType<ElemType>::InsertAt(const ElemType& item, int m_iPosition)
{
DBG_MSG(MSG_INFO, L"+ InsertAt");
assert ((m_iPosition >= 0) && (m_iPosition < m_iMaxSize));
m_pList[m_iPosition] = item;
m_iLength++;
DBG_MSG(MSG_INFO, L"- InsertAt");
}
int main()
{
DBG_MSG(MSG_INFO, L"+ This is main function");
CListType<int> CIntList(LIST_SIZE);
CListType<float> CFloatList(LIST_SIZE);
int iIndex;
int iNumber;
cout << ENTERINT;
for (iIndex = 0; iIndex < MAX_NUM; iIndex++)
{
cin >> iNumber;
CIntList.InsertAt(iNumber, iIndex); //insert the iNumber into the CIntList
}
cout << endl;
cout << SORT;
cout << endl;
CIntList.Sort(); //sort these iNumbers
CIntList.Print(); //display these numbers after sorting
float fNumber;
cout << ENTERFILOAT;
for (iIndex = 0; iIndex < MAX_NUM; iIndex