文章目录
数据结构与算法
1. 初识数据结构与算法
数据结构与算法听起来比较抽象,我个人的理解为用函数去操作一个有限的序列,序列中包含着数据元素,这些数据元素直接有着特定的关系集合。
2. 线性表
2.1 通过双向链表实现学生管理系统(C++)
双向链表:
代码:
#include<iostream>
#include<string>
#include<typeinfo>
#include <fstream>
#include<sstream>
#include <bits/stdc++.h>
#include <map>
using namespace std;
//链式储存结构
/***
*定义对象(学生)
*定义变量(年龄---)
*定义指针(双向指针方便于直接找到前驱)
*构造函数
***/
class Student{
public:
string name;
int age;
string sex;
Student *next=NULL;
Student *pre=NULL;
Student(string name1,int age1=18,string sex1="男"){
this->name=name1;
this->age=age1;
this->sex=sex1;
}
void Read(){
cout<<"姓名: "<<name<<" 年龄: "<<age<<" 性别: "<<sex<<endl;
}
};
Student *head=new Student("");
void Creat(){
string name1;int age1;string sex1; //============================异常检验
cout<<"姓名: ";cin>>name1;
cout<<"年龄: ";cin>>age1;
if(cin.fail()){
cin.clear();
cout<<