Co jest źle w szablonie tej metody? Wyskakuje runtime error, prawdopodobnie gdzieś jest wyjście poza przydzieloną pamięć.
template <class Type>
void linkedListType<Type>::deleteParticularNode(int k)
{
nodeType<Type> *current,*temp;
current=first;
if(0>k || k>length())
{
cout<<"Incorrect node number entered!";
return;
}
if(first==NULL)
{
cout<<"Cannot delete from an empty list\n";
return;
}
for(int i=1; i<k-2 ; i++)
current=current->link;
temp=current;
current->link=current->link->link;
delete temp;
temp=NULL;
count--;
}
Błąd:
An unhandled exception of type 'System.AccessViolationException' occurred in linked_list_ADT.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
testowa funkcja main
// linked_list_ADT.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "ordered_linked_list.h"
#define N 6
using namespace std;
int main()
{
unorderedLinkedList<int> listOfIntegers;
int tmp;
for(int i=0;i<N;i++)
{
cin>>tmp;
listOfIntegers.insertLast(tmp);
}
listOfIntegers.print();
cout<<endl;
//cout<<listOfIntegers.getParticularInfo(3);
cout<<endl;
listOfIntegers.deleteParticularNode(3);
listOfIntegers.print();
cout<<endl;
system("PAUSE");
return 0;
}