排序
【数据结构】链栈的基本操作(C++实现)
什么是链栈 链栈是一种基于链表实现的栈(Stack)数据结构。栈是一种后进先出(Last In, First Out,LIFO)的数据结构,而链栈通过链表的形式来组织栈中的元素。链栈与顺序栈相比,不需要预先分...
【C】while(y–);/while(y++);最终y是多少?
while(y--) #include <stdio.h> int main(){ int y=10; while(y--); printf('%d',y); return 0; } 答案:无论y一开始是多少,最终y都等于-1。 为什么? 因为非0即真+对于一个数如果一直+或者...
【模拟】各位相加
#include<iostream> using namespace std; int main(){ int num; cin >> num; while(num>9){ int total=0; while(num!=0){ total+=num%10; num/=10; } num = total; total = 0; } cout <&...
【C】复合赋值和递增递减
复合赋值 5个算术运算符,+-*/%,可以和赋值运算符“=”结合起来,形成复合赋值运算符“+=”、“-=”、“/=”和“%=” total += 5; total = total + 5; 注意两个运算符中间不要有空格 total += ...
【C】生成指定区间的随机数
As we all know,生成随机数需要使用srand和rand函数。srand用于初始化随机种子,一般使用当前系统时间作为种子初始化。 写做:srand(time(NULL));或者srand(time(0)); 要想生成指定区间的随机...
【C】判断回文数
#include <stdio.h> bool fun(int n) { int a = 0; int num = n; while (n > 0) { a = a * 10 + n % 10; n = n / 10; } if (a==num) { return true; } else { return false; } } int main() ...