Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to link list and I find it difficult to understand. Please help me explain each algorithm written in Link list.
C++
#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.
Posted
Updated 12-Aug-14 3:27am
v3
Comments
[no name] 12-Aug-14 9:36am    
Screaming at us doesn't help and asking us to explain the entire program here is outside of the scope of the forum. Go through some C++ tutorials.

You should first learn the basics of the C++programming language (for instance, you cannot ignore '*' and '->' operator meaning) and then try to understand the algorithm.
 
Share this answer
 
Sorry, but as you have marked virtually every line with a "what's this" I would suggest you get a C++ text book and read it. Search this site for recommendations of good C++ study books. For example:
Useful Reference Books[^]
 
Share this answer
 
Comments
Stefan_Lang 13-Aug-14 3:09am    
Exactly what I thought. This is not about linked list at all, this is about understanding C/C++!

Have a 5.
nv3 13-Aug-14 4:37am    
Thanks, Stefan.
See http://en.wikipedia.org/wiki/Linked_list[^], and then follow the advice of nv3 and CPallini.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900