C中的节点是什么? [英] What is a node in C?

查看:73
本文介绍了C中的节点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究CS50 pset5拼写器,在讲座中,他们介绍了一种称为节点的新东西.什么是节点?我真的不明白他们在视频中说的话.当我尝试使用Google搜索时,我看到了一些解释节点是什么的站点,但我并没有真正理解.我是c语言的新手,所以我不习惯所谓的编码单词".例如,我在有关节点的站点上发现了这一点:可以通过将大小增加一倍来扩展动态数组,但是复制旧数据和释放与旧数据结构相关的内存的操作会产生开销.strong>那是什么意思?请帮助我弄清楚什么是节点,因为它们似乎很重要且很有用,尤其是对于pset5.我的节点是这样定义的:

I'm working on cs50 pset5 speller, and in the lecture they introduce a new thing called nodes. What is a node? I didn't really understand what they said in the video. When I tried googling it, I got some sites that explained what a node is, but I didn't really understand. I'm new to c so I'm not accustomed to what I call 'coding words'. For instance, I found this on a site about nodes: A dynamic array can be extended by doubling the size but there is overhead associated with the operation of copying old data and freeing the memory associated with the old data structure. What is that supposed to mean? Please help me figure out what a node is because they seem important and useful, especially for pset5. My node is defined like this:

typedef struct node
{
    char word[LENGTH + 1];
    struct node *next;
}
node;

以下是拼写pset5演练的链接: https://cs50.harvard.edu/x/2020/psets/5/speller/

Here is the link to the walk-through of speller pset5: https://cs50.harvard.edu/x/2020/psets/5/speller/

推荐答案

节点是一种通用术语,用于演示单个块的链表或相关的数据结构.

Node is a common terminology that is used to demonstrate a single block of linked list or tree or related data structures.

为节点命名是一种惯例,否则您可以使用任何名称来调用它.

It is a convention to name it node, otherwise you can call it with any name.

C ++

struct node{
int data;
int *next;
};

或使用Python

class Node:
   def __init__(self, data, next= None):
       self.data = data
       self.next = next

但是您可以使用任何名称来调用

But you can call it with anyname

C ++

struct my_own_name{
int data;
int *nextptr;
};

或在python


class my_own_name:
    def __init__(self, data, next=None):
        self.data = data
        self.next = next

这篇关于C中的节点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆