这是我的代码.我很确定我已正确实现了链接列表,但我认为存在一些语法错误.
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct *node next;
};
void push(struct node** headRef, int data)
{
struct node* newNode;
newNode = malloc(sizeof(struct node));
newNode->data = data;
newNode->next = *headRef;
*headRef = newNode;
}
struct node* primeFactors(int num)
{
struct node* head = NULL;
if (num == 1)
{
return head;
}
int factor = 0;
int i = 2;
while (i <= num)
{
if (num % i)
{
factor = i;
}
}
push(&head, …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我的KeyListener只是没有响应KeyPressed事件.
如果重要,我在Ubuntu 12.04上.每按一次键就应该打印"按键",但不是.
这是代码:
import java.awt.event.*;
import javax.swing.*;
import java.awt.Graphics;
public class DisplayPanel extends JPanel
{
private Tile[][] tiles;
private Creature[] creatures;
private Dungeon dungeon;
private Player player;
public DisplayPanel(Dungeon dungeon, Tile[][] tiles, Creature[] creatures, Player player)
{
this.tiles = tiles;
this.creatures = creatures;
this.dungeon = dungeon;
this.player = player;
addKeyListener(new DungeonKeyListener());
requestFocus();
}
protected void paintComponent(Graphics g)
{
int maximum = (getWidth() < getHeight()) ? getWidth() : getHeight();
for (Tile[] row : tiles)
{
for (Tile tile : row) …Run Code Online (Sandbox Code Playgroud)