Can someone explain in details what this linked list do. I've been having trouble with linked list in c++. I understand it for the most part ,but I want to make sure im 100% correct. I've created some programs using linked list ,but for the most part its pure guessing and working around it. So can anybody please explain the following code to me in detail. Like the most detailed explanation will be nice if you have the time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Booksptr N = new Books;
N ->next = NULL;
N->Pages = AddData;
if (head != NULL)
{
curr = head;
while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = N;
}
else
{
head = N;
}
}
@keskiverto
Thanks I understand everything about link list in general.
Breakdown:
Does calling N, temp and curr in different parameters at the same time change the value of the functions altogether. Heres the code
(The Breakdown wasn't longer because I actually explained somethings to myself)
#include <iostream>
#include <vector>
//Coded by Justin Young
// If using code for website ask for permission
usingnamespace std;
class List
{
private:
typedefstruct Books
{
int Pages;
*Books next;
}*Booksptr;
Booksptr head;
Booksptr curr;
Booksptr temp;
public:
List();
void AddNode (int AddData);
void DeleteNode (int delData);
void PrintList ();
};
List::List()
{
head = NULL;
curr = NULL;
temp = NULL;
}
void List::AddNode(int AddData)
{
Booksptr N = new Books;
N ->next = NULL;
N->Pages = AddData;
if (head != NULL)
{
curr = head;
while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = N;
}
else
{
head = N;
}
}
void List::DeleteNode(int delData)
{
Booksptr delPtr = NULL;
temp = head;
curr = head;
while(curr != NULL && curr->Pages != delData){
temp = curr;
curr = curr->next;
}
if (curr = NULL){
cout << delData << "there were no books containing that " << endl;
delete delPtr;
}
else{
delPtr = curr;
curr = curr->next;
temp -> next = curr;
delete delPtr;
cout << "The value " << delData << "Was deleted " << endl;
}
}
int main()
{
}
If it's possible can someone just explain how the whole link list move in terms of linking. I got this code from a tutorial from Youtube. I just need some explanation as of how the node transverse througout the linked list. If that makes sense if not totally understandable I know I can be a bit confusing at times. To really say what I want to say is explain how parameters work in an Linked List.
--Blackhart