I'm new to link list and I find it difficult to understand. Please help me explain each algorithm written in Link list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include<stdlib.h>
#include<iostream>
using namespace std; //what's this?
typedef struct node //what's this?
{
int data; //what's this?
node *next; //what's this?
} Node; //what's this?
Node *createNode(int n) //what's this?
{
Node *ptr = new Node(); //what's this?
ptr->data = n; //what's this?
ptr->next = NULL; //what's this?
return ptr; //what's this?
}
Node *appendNode(Node *node, int n) //what's this?
{
Node *cur = node; //what's this?
while(cur)
{
if(cur->next == NULL) //what's this?
{
cur->next = createNode(n); //what's this arrows here?
return cur->next; //what's this?
}
cur = cur->next; //what's this?
}
return cur; //what's this?
}
void printNodes(Node *head) //what's this?
{
Node *cur = head; //what's this?
while(cur)//What is this I dont get it.
{
cout<< cur-> data<< " "; //what's this?
cur = cur->next; //what's this?
}
cout << endl;
}
Node *deleteNode(Node **head) //what's this?
{
Node *temp = *head; //what's this?
*head = temp->next; //what's this?
delete temp; //what's this?
return *head; //what's this?
}
Node *insertFront(Node **head, int n) //what's this?
{
Node *newNode = createNode(n); //what's this?
newNode->next = *head; //what's this?
*head = newNode; //what's this?
return *head; //what's this?
}
int main()
{
Node *head = createNode(100); //what's this?
appendNode(head, 200); //what's this?
appendNode(head, 300); //what's this?
printNodes(head); //what's this?
head = deleteNode(&head); //what's this?
printNodes(head); //what's this?
head = insertFront(&head, 100); //what's this?
printNodes(head); //what's this?
return 0; //what's this?
}
| |
OH I DON'T UNDERSTAND EVERYTHING. Please help me understand this LINK LIST.
Last edited on