Ok. I ended up redoing that function, and now it can delete from the end of the list(see code for new version). The only problem that I am having now is getting my search and insert function to insert a new assignment if it finds a date more than once instead of the list. When I
test this in main it doesn't printout everything that it should.
This is my delete function(all of my other functions haven't changed):
Code:
.
/*
Deletes an Assignment
*/
void List::DeleteAssign(string delData){
//if the list is empty at head.
if(head == NULL){
cout << "error cannot delete from empty list\n";
}else{
current = head;
while(current != NULL){
if(current->date == delData){
break;
}else{
previous = current;
current = current->next;
}
}
//case 2 node with name not found.
if(current == NULL){
cout << "name not found\n";
}else{
//deletes head node
if(head == current){
head = head->next;
}else{
//deletes beyond head.
previous->next = current->next;
}
cout << "The value " << delData << " was deleted\n";
delete current;
}
}
}
My main function tests:
Code:
#include <cstdlib>
#include "List3.h"
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
List assign;
assign.AddAssign("3/14/13","Statistics","43");
assign.AddAssign("3/12/13","Geometry","43");///3/12 deletes
assign.AddAssign("3/9/13","Calculus","45");
assign.AddAssign("3/12/13","Java","43");
assign.AddAssign("4/11/13","Biology","55");
assign.AddAssign("5/13/13","Economics","77");
assign.AddAssign("3/11/13","English 101","100");
assign.AddAssign("3/9/13","French","86");//inserts physics
assign.AddAssign("5/23/13","Spanish","55");
assign.AddAssign("3/3/13","Biology","55");
cout << "Printing list...\n";
assign.PrintList();
//deletes two assignments from list
cout << "Deleting assignments with 3/12/13\n";
assign.search_and_remove("3/12/13");
cout<< "New list without dates 3/12/13\n";
assign.PrintList();
//Does not work with two of the same dates in list
cout << "search assignments with dates 3/9/13\n";
assign.search_and_insert("3/9/13","3/24/13","PhysicsII","89");
cout << "updated list with inserted assignment"
" 3/24/13 PhysicsII 89 \n";
assign.PrintList();
cout << "End of list. \n";
return 0;
//Should print out this list:
// instead it leaves out the assignments in bold..
/*
3/14/13,Statistics,43
3/9/13,Calculus,45
* 3/24/13,PhysicsII,89
4/11/13,Biology,55
5/13/13,Economics,77
3/11/13,English 101,100
3/9/13,French,86
* 3/24/13,PhysicsII,89
* 5/23/13,Spanish,55
3/3/13,Biology,55
*/
}