我在公共文件夹中有一些图像,我/public/link/to/image.jpg在控制器中获取了url .我想在我的视图中显示它,所以我将url传递给视图.
但是如何在网页上显示呢?
我搜索了帖子,其中大部分与存储在assets文件夹中的照片有关,可以<%= image_tag image-url (filename) %>在视图中检索.
那么如何在视图中的公共文件夹中显示图像?
我有一个链表
struct node {
data_t data;
node_t *next;
};
typedef struct {
node_t *head;
node_t *foot;
node_t *curr; // for iterator
unsigned int size;
} list_t;
Run Code Online (Sandbox Code Playgroud)
有了这个结构,就说我定义了一个列表
list_t* myList;
Run Code Online (Sandbox Code Playgroud)
如何使用GDB打印整个链表?
我知道有两种表示图形的方法:一种是使用矩阵,另一种是使用列表.
如果我使用矩阵,我必须翻转矩阵中的所有位.这不是需要O(V ^ 2)时间吗?
如果我使用列表,我不是必须逐个遍历每个列表,并创建一个新集合吗?这似乎需要O(V + E)时间是线性的.我对么?
所以,我在这里有另一个问题.例如,考虑我在我的图形上使用Dijkstra算法(矩阵或列表),并且我们使用优先级队列作为场景后面的数据结构.图表表示与数据结构的使用有关系吗?它会影响算法的性能吗?
假设我使用Dijkstra算法的表示和优先级队列列表,Dijkstra的矩阵和使用优先级队列之间会有区别吗?
我想makeQueue这只与手术有关?或者他们没有什么不同?
我想从右边添加两个不同长度的列表这里是一个例子
[3, 0, 2, 1]
[8, 7]
Run Code Online (Sandbox Code Playgroud)
预期结果:
[3, 0, 10, 8]
Run Code Online (Sandbox Code Playgroud)
这些列表表示多项式的系数
这是我的实施
class Polynomial:
def __init__(self, coefficients):
self.coeffs = coefficients
def coeff(self, i):
return self.coeffs[-(i+1)]
def add(self, other):
p1 = len(self.coeffs)
p2 = len(other.coeffs)
diff = abs(p1 - p2)
if p1 > p2:
newV = [sum(i) for i in zip(self.coeffs, [0]*diff+other.coeffs)]
else:
newV = [sum(i) for i in zip([0]*diff+self.coeffs, other.coeffs)]
return Polynomial(newV)
def __add__(self, other):
return self.add(other).coeffs
Run Code Online (Sandbox Code Playgroud)
这一个工作正常,只是想知道无论如何做更好,更清洁的代码?由于python总是在干净的代码上强调,我想知道有没有办法编写更干净的pythonic代码?
我可以清楚地看到,N ^ 2受到c2 ^ N的限制,但我如何通过使用big-O的形式定义来证明它.我可以通过MI简单地证明这一点
这是我的尝试..根据定义,对于任何n> n0,存在一个常数C,其中f(n)<= Cg(n)其中f(n)= n ^ 2且g(n)= 2 ^ n
我应该记录到两边并解决C?
还有一个关于斐波纳契序列的问题,我想解决递归关系.
int fib(int n){
if(n<=1) return n;
else return fib(n-1) + fib(n-2);
Run Code Online (Sandbox Code Playgroud)
等式是......
T(n) = T(n-1)+T(n-2)+C // where c is for the adding operation
所以T(n) = T(n-2) + 2T(n-3) + T(n-4) + 3c
还有一个
T(n) = T(n-3) + 3T(n-4) + 3T(n-5) + T(n-6) + 6c
然后我开始迷失形成一般方程式我的模式有点像帕斯卡三角形?
t(n) = t(n-i) + aT(n-i-1) + bT(n-i-2) + ... + kT(n-i-i) + C 这是我的显示 gdb
(gdb) x/20bx 0xbffff2c0
0xbffff2c0: 0xd4 0xf2 0xff 0xbf 0x16 0x8f 0x04 0x08
0xbffff2c8: 0x05 0x00 0x00 0x00 0x00 0x00 0x0c 0x42
0xbffff2d0: 0x6b 0x00 0x00 0x00
Run Code Online (Sandbox Code Playgroud)
是否可以将其更改为连续 4 个字节?
#include <video_defines.h>
#include <stdio.h>
#include <stdint.h>
#include <x86/asm.h>
#define HIDDEN 1
#define NOT_HIDDEN 0
typedef struct{
int row;
int col;
int color;
int cursor;
}console_info;
/* Setting up console info */
console_info *console;
console->row = 0;
console->col = 0;
console->color = (FGDN_WHITE | BKGN_BLACK);
console->cursor = NOT_HIDDEN;
Run Code Online (Sandbox Code Playgroud)
对于为什么会出现这些错误一无所知.
console.c:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
console.c:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
console.c:21: error: expected '=', ',', ';', 'asm' or …Run Code Online (Sandbox Code Playgroud) 所以我有一个8字节的数据结构
typedef struct __attribute__((__packed__)) entry{
// something here total 64 bits;
}entry_t;
Run Code Online (Sandbox Code Playgroud)
我有一个void* base指向我要放入条目的基地的指针.
将
entry_t a;
*base = a;
Run Code Online (Sandbox Code Playgroud)
做这个工作?
或者我必须将指针投射到指针entry_t?
更新
对不起我没有提到我不能使用memcpy,因为我使用的内核还没有实现memcpy.