我在创建链接列表时遇到了一些问题,还有一些我正在尝试的帮助函数.我的代码如下:
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "getNextWord.h"
#define MAX_WORD_SIZE 256
typedef struct{
int counter;
char* key;
struct node* next;
} node;
node* createNode(char* words){
node* head;
if(!(head=malloc(sizeof(node)))) return NULL;
head->key=words;
head->next=NULL;
return head;
}
node* addToList(node* head, char* words){
node* newNode;
newNode=createNode(words);
newNode->next = head;
return newNode;
}
int find(node* head){
if (head->next != NULL){
node* next = head->next;
while(head != NULL){
if (strcmp(head->key,next->key)==0){
head->counter++;
head=head->next;
return 1;
}
else{
head=head->next;
}
}
} …Run Code Online (Sandbox Code Playgroud) 对不起,我在这里有一个主要的大脑放屁(猜测这是几天的小睡眠让你).如果不将任何内容更改为静态,我如何创建一个将运行此命令的main().
package merger;
import java.util.Random;
public class another {
public int[] numbers;
private final static int size = 100;
private static int maxNumber = 30;
private final static int limit = 10;
public int number;
private boolean Insertion = false;
public void arraytosort(){
numbers = new int[size];
Random number = new Random();
for (int i=0; i< numbers.length; i++){
numbers[i] = number.nextInt(maxNumber);
}
test(numbers);
}
public void test(int[] array){
this.numbers = array;
number = array.length;
mergesort(0,number - 1);
}
public void …Run Code Online (Sandbox Code Playgroud)