Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Forked from anonymous/main.cpp
Last active December 15, 2015 17:29
Show Gist options
  • Save rhysforyou/5296619 to your computer and use it in GitHub Desktop.
Save rhysforyou/5296619 to your computer and use it in GitHub Desktop.
/**********************************************************************
* linkedlist.cpp - CSCI212 - Ass1 - Contains LinkedList class definition
* Anthony Burchell-Bailey - 4245490 - /4/2013
**********************************************************************/
#include <iostream>
#include <cstddef>
#include <string>
#include "linkedlist.h"
#include <iomanip>
using namespace std;
LinkedList::LinkedList()
{
Head = NULL;
}
LinkedList::~LinkedList()
{
while(Head != NULL)
{
PNode curr = Head;
Head = Head->next;
delete curr;
}
}
void LinkedList::AddToTail(string newdata, int newdate, int newtim, float newsize)
{
PNode tmp, curr;
// create a new customer and store the information
tmp = new node;
tmp->name = newdata;
tmp->file = 1;
tmp->ODate = newdate;
tmp->OTim = newtim;
tmp->NDate = newdate;
tmp->NTim = newtim;
tmp->Size = newsize;
tmp->next = NULL;
// add to the end of the list if the list is not empty
if (Head != NULL)
{
curr = Head;
while(((*curr).name).compare(newdata) != 0)
{
if(((*curr).name).compare(newdata) > 0)
{
tmp->next = Head;
Head = tmp;
}
else
{
while(((*curr).name).compare(newdata) < 0 && curr->next)
{
curr = curr->next;
if((*curr).name.compare(newdata) == 0)
{
break;
}
}
if(((*curr).name).compare(newdata) == 0)
{
break;
}
tmp->next = curr->next;
curr->next = tmp;
}
break;
}
if(((*curr).name).compare(newdata) == 0)
{
(*curr).file += 1;
(*curr).Size += newsize;
if((*curr).ODate < newdate)
{
(*curr).ODate = newdate;
}
if((*curr).NDate > newdate)
{
(*curr).NDate = newdate;
}
}
}
else
Head = tmp;
}
void LinkedList::Print()//prints list. eg 12 34 21 26
{
PNode ins = Head;
double tsize = 0;
string unit = "B";
string Aname = "ALL";
int afile = 0;
int aodate = ins->ODate;
int andate = ins->NDate;
int asize = 0;
while(ins)
{
unit = "B";
afile += ins->file;
asize += ins->Size;
tsize = ins->Size;
if(ins->ODate < aodate)
{
aodate = ins->ODate;
}
if(ins->NDate > andate)
{
andate = ins->NDate;
}
// cout << ins->name << "\t" << ins->file << "\t";
printf("%s\t%d\t", ins->name.c_str(), ins->file);
// cout << ins->ODate << "\t" << ins->NDate << "\t";
printf("%d\t%d\t", ins->ODate, ins->NDate);
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "KB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "MB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "GB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "TB";
}
}
}
}
cout << setprecision(4) << tsize << unit << "\n";
ins = ins->next;
}
tsize = asize;
unit = "B";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "KB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "MB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "GB";
if(tsize > 9999)
{
tsize = tsize / 1024;
unit = "TB";
}
}
}
}
cout << endl;
cout << Aname << "\t" << afile << "\t" << aodate << "\t" << andate << "\t" << setprecision(4) << tsize << unit;
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment