So I've been searching forums, but im still very new to the language and linked lists so I can barely decipher the results.
basically I made a delete function for my linked list.
I can currently Create a list, traverse the list, sort the list, search the list, and insert before any node in the linked list. I recycled some code from the insert to locate the point in the list where I could delete. My main point of confusion is how to link the previous points to the node that is after the one I am deleting.
my code looks like this
I really am looking to learn but hours of drawing this out is not really helping me..
This is the structure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
#include<stdlib.h>
usingnamespace std;
struct nodetype // defines user data type
{ // which is the node for the linked list
int adata;
nodetype *ptr;
};
void acreate(nodetype *&start); // passing reference parameter (*& for reference parameter)
void atraverse(nodetype *start); // passing a value parameter
void asort(nodetype *start);
bool asearch(nodetype *start);
void ainsert(nodetype *start);
void adelete(nodetype *start);
void amenu();
nodetype *entry, *last, *next;
int akey;
entry=start->ptr;
last=start;
next=last->ptr;
cout<<"Input Data You Would Like To Delete"<<endl;
cin>>akey;
while((akey!=entry->adata)&&(entry->ptr !=NULL))
{
if(entry->adata==akey)
{
entry=last->ptr;
last->ptr=next->ptr;
delete entry;
}
}
}
Use it as a private service function inside of proper public method which will search for needed nodes, make sure that all pointers points where they should etc.