本文介绍了如何理解C ++中的链接列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是链接列表的新手,我觉得很难理解。请帮我解释链接列表中编写的每个算法。

I'm new to link list and I find it difficult to understand. Please help me explain each algorithm written in Link list.

#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我不理解一切。请帮助我理解这个链接列表。


OH I DON'T UNDERSTAND EVERYTHING. Please help me understand this LINK LIST.

推荐答案




这篇关于如何理解C ++中的链接列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:39