找到 7345 篇文章 关于 C++

C++程序实现优先队列

Chandu yadav
更新于 2019-07-30 22:30:23

6K+ 阅读量

队列的实现方式是 FIFO,其中插入操作在队列的一端(后端)进行,删除操作在另一端(前端)进行。第一个进入的元素首先被删除。队列操作包括:EnQueue (int data):在后端插入int DeQueue():从前端删除但是优先队列不遵循先进先出,而是每个元素都有一个基于紧急程度的优先级。具有相同优先级的项目以先进先出的服务方式处理。优先级较高的项目优先于其他优先级较低的项目进行处理。类描述开始    类 Priority_Queue 具有以下函数:    函数 insert() 用于在... 阅读更多

C++程序实现循环队列

Arjun Thakur
更新于 2020-06-25 09:19:29

28K+ 阅读量

队列是一种抽象数据结构,包含一系列元素。队列实现 FIFO 机制,即第一个插入的元素也是第一个被删除的元素。循环队列是一种队列类型,其中最后一个位置连接到第一个位置形成一个圆圈。下面给出了一个在 C++ 中实现循环队列的程序 -示例#include using namespace std; int cqueue[5]; int front = -1, rear = -1, n=5; void insertCQ(int val) {    if ((front == 0 && rear == n-1) || (front == rear+1)) {       cout

C++ 中的纯函数

Ankith Reddy
更新于 2020-06-25 09:20:34

3K+ 阅读量

纯函数对于相同的参数值始终返回相同的结果。它们只返回结果,并且没有额外的副作用,例如修改参数、I/O 流、生成输出等。一些纯函数包括 sin()、strlen()、sqrt()、max()、pow()、floor() 等。一些非纯函数包括 rand()、time() 等。一些演示一些纯函数的程序如下 -strlen()strlen() 函数用于查找字符串的长度。这在下面的程序中演示 -示例 在线演示#include #include using namespace std; int main() {    char str[] = "Rainbows are beautiful";    int count = ... 阅读更多

C++ 中的 iscntrl() 函数

Arjun Thakur
更新于 2020-06-25 09:22:26

98 阅读量

C++ 中的 iscntrl() 函数检查字符是否为控制字符。此函数在 ctype.h 中定义。iscntrl() 函数的语法如下所示 -int iscntrl ( int ch );这里,ch 是需要检查的字符。下面给出了一个通过计算字符串中控制字符数量来演示 iscntrl() 函数的程序 -示例 在线演示#include #include using namespace std; int main() {    char str[] = "Coding\tis\tfun";    int i, count = 0;    for(i=0; str[i]!='\0';i++) {       if(iscntrl(str[i]))       count++;    }    cout

C++程序计算两个时间段之间的差值

Chandu yadav
更新于 2020-06-25 09:25:10

2K+ 阅读量

以小时、分钟和秒的形式提供了两个时间段。然后计算它们的差值。例如 -时间段 1 = 8:6:2 时间段 2 = 3:9:3 时间差为 4:56:59下面给出了一个计算两个时间段之间差值的程序 -示例 在线演示#include using namespace std; int main() {    int hour1, minute1, second1;    int hour2, minute2, second2;    int diff_hour, diff_minute, diff_second;    cout minute1 >> second1;    cout minute2 >> second2;    if(second2 > second1) {       minute1--;       second1 ... 阅读更多

C++程序使用引用调用按循环顺序交换数字

George John
更新于 2020-06-25 09:26:39

994 阅读量

可以通过使用引用调用将三个数字传递给函数 cyclicSwapping() 来按循环顺序交换它们。此函数以循环方式交换数字。下面给出了使用引用调用按循环顺序交换数字的程序 -示例 在线演示#include using namespace std; void cyclicSwapping(int *x, int *y, int *z) {    int temp;    temp = *y;    *y = *x;    *x = *z;    *z = temp; } int main() {    int x, y, z;    cout > y >> z;    cout

C++ 中的静态数据成员

Ankith Reddy
更新于 2020-06-25 09:29:34

23K+ 阅读量

静态数据成员是使用 static 关键字声明的类成员。即使有多个类对象,类中也只有一个静态数据成员的副本。这是因为所有对象共享静态数据成员。当创建第一个类对象时,静态数据成员始终初始化为零。静态数据成员的语法如下所示 -static data_type data_member_name;在上面的语法中,使用了 static 关键字。data_type 是 C++ 数据类型,例如 int、float 等。data_member_name 是提供给... 阅读更多

C++ 中的 isspace() 函数

Arjun Thakur
更新于 2020-06-25 09:31:06

3K+ 阅读量

isspace() 函数是 ctype.h 中的预定义函数。它指定参数是否为空格字符。一些空格字符包括空格、水平制表符、垂直制表符等。下面给出了一个通过计算字符串中空格数量来实现 isspace() 函数的程序 -示例 在线演示#include #include using namespace std; int main() {    char str[] = "Coding is fun";    int i, count = 0;    for(i=0; str[i]!='\0';i++) {       if(isspace(str[i]))       count++;    }    cout

C++ 中的多重继承

Chandu yadav
更新于 2020-06-25 09:03:09

6K+ 阅读量

当一个类从多个基类继承时,就会发生多重继承。因此,类可以使用多重继承从多个基类继承特性。这是面向对象编程语言(如 C++)的一个重要特性。下面给出了一个演示多重继承的图表 -下面给出了一个在 C++ 中实现多重继承的程序 -示例 在线演示#include using namespace std; class A {    public:    int a = 5;    A() {       cout

C++ 中的 strstr()

George John
更新于 2020-06-25 09:04:00

1K+ 阅读量

strstr() 函数是 string.h 中的预定义函数。它用于查找字符串中子字符串的出现位置。此匹配过程在 '\0' 处停止,并且不包含它。strstr() 的语法如下所示 -char *strstr( const char *str1, const char *str2)在上面的语法中,strstr() 查找字符串 str1 中字符串 str2 的第一次出现位置。下面给出了一个实现 strstr() 的程序 -示例 在线演示#include #include using namespace std; int main() {    char str1[] = "Apples are red";    char str2[] = "are";    char *ptr;    ptr = strstr(str1, str2);    if(ptr)    cout

广告
© . All rights reserved.