快速排序:
计数排序:
快速排序和计数排序都是稳定的算法.
如果存在这两个条件,为什么快速排序仍然比计数排序更好?
这是我在头文件中的代码:
typedef struct _aaa
{
static void do_something(t_bbb *b); //this line is problematic
} t_aaa;
typedef struct _bbb
{
t_aaa *a;
} t_bbb;
Run Code Online (Sandbox Code Playgroud)
但它说:
未知的类型名称
t_bbb
如何使代码可编辑?
我正在尝试让C程序的用户输入M代表男性,F代表女性,并在不符合M或F的情况下循环通过。下面我尝试了以下代码,但是它循环两次给出正确的答案。例如,输入M后循环并打印
性别为假,请输入M(男)和M(女)
有什么办法可以解决它。
目的是如果用户输入M或F,它将可以工作而无需再次输入。
如果有其他问题可能会问很多次
#include "Gender.h"
#include<stdio.h>
char sex;
void Gender(){
printf("\nEnter Student Gender ('example M for Male F for Female):\n");
scanf(" %s",&sex);
while (sex != "M" || sex != "M"){
printf ("\n FALSE gender .. please enter M for Male and M for Female:\n");
scanf(" %s",&sex);
printf("\nStudent Sex :%c", sex,"\n");
return;
}
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的输入,每行一个单元格:
[0,0]
[0,2]
[0,4]
[2,4]
[4,4]
Run Code Online (Sandbox Code Playgroud)
我设法使用类似的方法逐一阅读它们,[%d,%d]并得到如下输出:
cell1: row: 0, col:0
cell1: row: 0, col:2
Run Code Online (Sandbox Code Playgroud)
然后我有另一个像这样的输入
[0,0]->[0,1]->
[0,2]->[0,3]->
[0,4]->[1,4]->
[2,4]->[3,4]->
[4,4]->[5,4]
Run Code Online (Sandbox Code Playgroud)
如何在不被箭头'打断的情况下读取输入->'?
在读/写操作期间是否绝对有必要检查feof()?
我问的原因是因为我有一个执行读/写一次的程序,下面是代码:
while (1) {
data = read_file_data(file);
write_file_data(data, filename);
if (feof(file))
print(read error)
}
Run Code Online (Sandbox Code Playgroud)
这只是伪代码,但是是否有必要检查feof()像这样一次读取的情况?目前,我认为只有当您在上面的阅读之后再阅读一遍时才有必要,如下所示:
while (1) {
data = read_file_data(file);
write_file_data(data, filename);
if (feof(file)) // feof error occurred oops
print(read error)
data = read_file_data(file); // reading after error
}
Run Code Online (Sandbox Code Playgroud)
EOF reached最后,即使发生错误(读过去) ,阅读会产生什么后果EOF?
我正在尝试释放一堆不同类型的东西,所以我认为我可以通过将它们添加到一堆void *单元格中使用一个函数来释放所有它们。
我的问题是:保存SDL_Surface*asvoid *并使用该free()函数而不需要是否安全SDL_FreeSurface()?
头文件:
// pe10-8arr.h -- header file for a simple list class
#ifndef SIMPLEST_
#define SIMPLEST_
// program-specific declarations
const int TSIZE = 45; // size of array to hold title
struct film
{
char title[TSIZE];
int rating;
};
// general type definitions
typedef struct film Item;
const int MAXLIST = 10;
class simplist
{
private:
Item items[MAXLIST];
int count;
public:
simplist(void);
bool isempty(void);
bool isfull(void);
int itemcount();
bool additem(Item item);
void transverse( void (*pfun)(Item &item));
};
#endif
Run Code Online (Sandbox Code Playgroud)
代码使用标题:
#include "pe10-8arr.h" …Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
int main(){
int l,m,q,j;
char option;
scanf("%d",&q);
printf("%d\n",q);
for(j=0;j<q;j++){
scanf("%c %d %d",&option,&l,&m);
printf("%c %d %d",option,l,m);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
3(Input)
3
C 1 4(Input)
0 -374066224C 1 4
Run Code Online (Sandbox Code Playgroud)
上面的代码有什么问题?它没有给出预期的输出.
说我有一个文件夹"root".我拥有这个文件夹,我这样做是为了其他人(包括用户"user2",权限是rx)
在root中我有另一个文件夹"bin".我将"bin"的所有者更改为用户"user2",并授予他rwx权限.
以下不起作用:
DECLARE @jake varchar(30);
SET @jake='$%$^$%'
SELECT [PlayerID], [Nickname], [UserName], [ClubNumber],
[FirstName], [Email], [LastName], [DOB]
FROM [Players]
WHERE ***** LIKE'%'+@jake+'%'
ORDER BY lastname ASC
Run Code Online (Sandbox Code Playgroud)
我试图使用*for all列,所以我不必使用或命令列出它们.有任何想法吗?