我用C语言实现了一个链表。下面是我创建的一个结构,它代表了链表:
typedef struct llist {
struct lnode* head; /* Head pointer either points to a node with data or NULL */
struct lnode* tail; /* Tail pointer either points to a node with data or NULL */
unsigned int size; /* Size of the linked list */
} list;
"llist“基本上是没用的。
我有下面的链表结构:
struct Node {
int type;
int otherInfo;
Node * next;
}
我想创建一个排序的(最终)链表,跟踪每个"type“出现的次数。示例节点为:
struct Node2 {
int type;
int frequency;
//A linked list to keep track of the "otherInfo"
Node2 * next;
}
我目前的算法是O(n^2),这是不合理的,因为原始链表有时可以有超过30,000个元素。有没有更有效的
我在Windows上使用的是MinGW。我正在构建链表,我对此感到困惑。
#include <stdio.h>
#include <stdlib.h>
typedef struct Data
{
int x;
int y;
struct BlaBla * next; /*compiles with no problem*/
}List;
int main(void)
{
List item;
List * head;
head = NULL;
return 0;
}
现在,struc
我开始掌握链表是如何在C中工作的,我对如何构建一个为链表生成新元素的函数有疑问: struct elem{
int data;
struct elem* next;
};
typedef struct elem* listEl; // we call data type pointer to an element listEl;
//how to create an element
listEl createElem1(){
listEl temp;
temp = malloc(sizeof(struct elem));
(*temp).data = 0;
class node{
public:
int key;
int data;
node* next;
node()
{
data = 0;
key = 0;
next = NULL;
}
node(int k, int d)
{
data = d;
key = k;
}
};
我见过在不使用键的情况下编写链表,使用索引遍历链表的代码。但是如果我们比较这两种情况的空间和时间复杂度,哪一种更好?