Could somebody help me understand this linklist project that my professor gave us as an example in c++. I just cannot understand most of the logic of the statements in it. http://www.filedropper.com/linklistproject
I am totally lost with link list
linked list*
@Preetha
@TheSmartOne
@Zarkon
A linked list is a list where each node contains a value and a pointer to the next node. If the pointer is null, that's the last node of the list. The first node of the list is called either the head or the root of the list. They're advantageous because nodes can be scattered all over memory and it doesn't matter. They stink because searching can only be done in a linear fashion, starting at the root. Your project has two header files (.h) and two C++ source files (.cpp). Header files declare the headers of classes, member functions (methods) and variables which can be defined in corresponding C++ files. In C++, when memory is dynamically allocated for struct(ure)s or classes, you address member functions or member variables with "->". In static memory, you'd use a period. The rest of it is just C++. If you have any more specific questions, feel free.
@blackstreet23 Is this like a topic where you can talk about scripts,coding and what not?
I am lost in the delete function void List::Delete(int data) { // Create a temp pointer Node *tmp = head; // No nodes if ( tmp == NULL ) return; // Last node of the list if ( tmp->Next() == NULL ) { delete tmp; head = NULL; } else { // Parse thru the nodes Node *prev; do { if ( tmp->Data() == data ) break; prev = tmp; tmp = tmp->Next(); } while ( tmp != NULL ); // Adjust the pointers prev->SetNext(tmp->Next()); // Delete the current node delete tmp; } }
yes. I am trying to understand my professor's code for me to be able to write another program based on it. Also, i need to understand it to study for a test.
@rsmith6559
Think of each element in a linked list as comprising of 2 cells as shown here: |dw:1457390649738:dw|
Join our real-time social learning platform and learn together with your friends!