- 博客(12)
- 收藏
- 关注
原创 Java的数据类型和常用运算符
目的:熟悉Java的数据类型和常用运算符 public static void main(String[] args) { //main函数 char testLetter ='试'; String testLetters="试验"; System.out.println("char用单引号,是一个字符: " + testLetter);
2016-12-14 08:07:33
196
原创 Java中的类和对象
目的:比较C++和Java的类public static void main(String[] args) { //main函数 class Student{ String name; int age; float score; void say(){
2016-12-13 13:07:53
157
原创 第一个Java程序
目的:了解Java的结构和语法public class JavaApplication4 { //程序名,就是class public static void main(String[] args) { //main函数 System.out.println("Hello World!"); //输出结果 }}编程收获:1. c++的string是小写
2016-12-13 03:53:13
181
原创 vector初步:初始化和显示数值
目的: 练习vector的用法,包括初始化,和显示数值#include #include //说明使用vectorusing namespace std;int main(){ //vector的初始化方法之一: vector v1; for (int i = 0; i < 10; i++) v1.push_back(i); //v1放在前面,i放在括号里,给v1的每
2016-12-12 14:41:27
419
原创 对一个数组元素排序,对应的数组元素排序
目的:对一个数组元素排序,对应的数组元素排序比如一个数组为单词,另一个数组为每个单词的字母数。用一个函数对它们进行对应排序#include #include using namespace std;template void matchSort(type* array1, int* array2, int size)//比较两个数组,按照对应顺序从大到小排列另一个数组{
2016-12-05 15:28:44
1142
原创 用自建的函数给数组排序
目的:不使用algorithm库里的sort函数,自建函数给数组排序,包括从大到小,或者从小到大这里用了设计了三个函数,一个是只管把数组从小到大排序,一个是只管从大到小排序,第三个函数是增加一个参数,可以用它来对数组做两种排序#include #include using namespace std;template void sortArraytoBigger(type a
2016-12-05 14:53:04
616
原创 可以常用的函数模板:打印数组
目的: 用数组编程的时候,往往要打印数组的内容。可以设置一个模板输出函数的内容#include #include using namespace std;template //做成模板,用于各种类型的数组。使用模板只要增加这一行,并改动下面相应的class类型即可void printArray(Type A[], int size) //参数是数组名和数组的长度{ for (in
2016-12-05 14:14:11
1513
原创 结构体指针怎么用-简单的链表
目的:用结构体指针做一个简单的链表#include #include using namespace std;struct student{ int ID; string name; student *next; //增加一个结构体指针,做一个链表结构};int main(){ student stuA, stuB, stuC;//定义三个对象 stud
2016-11-23 10:04:12
1593
原创 结构体指针怎么用
目的:利用结构体指针输出同一个学生的学号#include #include using namespace std;struct student{ int ID; string name;};int main(){ student stu; student *p = &stu;//定义结构体指针,并初始化。这步一定要有,有指针就要有对应的对象。不能光定义指针。
2016-11-23 09:39:33
622
原创 把字符串分成字符串数组-用结构体返回数组
目的:把一个带逗号的字符串比如“”aa,bbb,cc,dd“”分成四个小的字符串,利用结构体返回一个数组#include #include using namespace std;class getArray //1. 设置一个结构体class getArray来存放数组,优点是比指针安全,缺点是处理大量数据时效率不高{public: string temp[4];
2016-11-19 09:54:09
747
原创 把字符串分成字符串数组-用指针返回数组
目的:把一个带逗号的字符串比如“”aa,bbb,cc,dd“”分成四个小的字符串,作为一个数组返回#include #include using namespace std;string* split(string input) //1. 要返回string * 类型的结果{ string *temp; temp=new string[4]; // 2. 用这两
2016-11-19 08:57:41
356
原创 把字符串分成字符串数组- 用void函数直接打印结果,不用返回值
目的:把一个带逗号的字符串比如“”aa,bbb,cc,dd“”分成四个小的字符串#include #include using namespace std;void split(string input){ string temp[4]; //长字符串分成4段小字符串 int j= 0; for (unsigned i = 0; i < inp
2016-11-18 13:28:37
553
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人