1 线程状态1.1 状态介绍当线程被创建并启动以后,它既不是一启动就进入了执行状态,也不是一直处于执行状态。线程对象在不同的时期有不同的状态。那么Java中的线程存在哪几种状态呢?Java中的线程
状态被定义在了java.lang.Thread.State枚举类中,State枚举类的源码如下:
123456789101112131415161718192021222324252627282930public class Thread { public enum State { /* 新建 */ NEW , /* 可运行状态 */ RUNNABLE , /* 阻塞状态 */ BLOCKED , /* 无限等待状态 */ WAITING , /* 计时等待 */ TIMED_WAITING , /* 终止 */ TERMINATED; } ...
学生管理系统:增删改查Main.java123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182import java.util.ArrayList;import java.uti ...
模拟双色球1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import java.util.Random;import java.util.Scanner;public class Main { static Random random = new Random(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int[] winCode = new int[7]; int[] userCode = new int[7]; int countBlue = 0, countRed = 0; winCode(win ...
奇怪的捐赠地产大亨 Q 先生临终的选愿是:拿出 100 万元给 X社区的后民抽奖,以稍忘藉心中愧疚。 麻烦的是,他有个很奇怪的要求:
1.100 万元必须被正好分成若干份(不能剩余)。每份必须是了的若干次方元。比如:1元:7元,49元,343 元,
2.相同金额的份数不能超过5 份。
3.在满星上述要求的情况下,分成的份数越多越好请你帮忙计算一下,最多可以分为多少份?
123456789101112131415161718192021222324252627#include <stdio.h>int main(){ int money = 1000000, time = 0; while (money > 0) { if (money % 7 == 0) { money /= 7; } { int i = 1; for (i; i <= 5; i++) { money--; if (money %7== 0) { break; } ...
顺序栈123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define MAX 10typedef struct SqStack { int data[MAX]; int top;}SqStack;//初始化栈bool InitStack(SqStack* q){ q->top = -1; return true;}//判断栈是否为空bool StackEmpty(SqStack* q){ if (q->top == -1) return true; else return false;}//判断栈是否已满bool StackFull(SqStack* q){ if (q->to ...
顺序队列12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#include<stdio.h>#include<stdlib.h>#include<stdbool.h>#define MAXSIZE 10//定义顺序队列typedef struct SqQueue { int data[MAXSIZE]; int front, rear; int size;} SqQueue;//初始化顺序队列bool InitQueue(SqQueue* q) { q->front = q->rear =q->size= 0; return true;}//队列判空bool QueueEmpty(SqQueue* q){ if (q->size == 0) { return true; } ...
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374#include<stdio.h>#include<stdlib.h>#include<stdbool.h>typedef struct LinkNode { int data; LinkNode* next;}LinkNode;typedef struct{ LinkNode* front,*rear;}LinkQueue;//初始化链式队列bool InitQueue(LinkQueue *Q) { Q->front=Q->rear=(LinkNode *)malloc(sizeof(LinkNode)); if (Q->front==NULL) { return false; } Q ...
顺序表的增删改查1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#include<stdio.h>#include<stdlib.h>#include <stdbool.h>#define N 10typedef struct { int* arr; int arr_length; int length_max;} list;bool init_list(list* list1){ list1->arr = (int*)malloc(N * sizeof(int)); if (list1->arr == NULL) { return false; } list1->arr_length = 0; list1->le ...
单链表的增删改查123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152#include<stdio.h>#include<stdlib.h>#include<stdbool.h>typedef struct LNode { int data; struct LNode *next;}LNode,*Li ...
常规:
123456789101112131415161718192021222324252627282930#include "iostream"using namespace std;int main() { int length; cout << "请输入数组长度:"; cin >> length; int *arr = new int[length]; cout << "请输入数组元素:" << endl; for (int i = 0; i < length; i++) { cin >> arr[i]; } //选择排序 for (int i = 0; i < length - 1; i++) { int minIndex = i; for (int j = i + 1; j < length; j++) ...