2020.12.14数据结构-课程设计

本文介绍了数据结构课程设计的内容,包括使用C语言实现的线性表员工管理系统、栈和队列解决迷宫问题、二叉排序树和二叉平衡树的创建与操作,以及图型结构题目——行车路线的最小疲劳度路径规划。此外,还涉及了文件操作,如学生信息二叉排序树管理系统的存盘和取盘功能。
摘要由CSDN通过智能技术生成

几万字长文预警~~


一、线性表:员工管理系统

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//数据结构课设:线性表-员工管理系统
const int N = 1e7 + 7;
int input_type, cnt_man;
ll cnt[N];

struct node
{
   
    char name[15];       //姓名     可排序
    char department[18]; //单位
    char gender[20];     //性别
    char post[20];       //职务
    char site[20];       //住址
    ll age;              //年龄     可排序
    ll telephone;        //电话
    ll wage;             //工资     可排序
    ll num;              //职工号   可排序

    struct node *next;
} men[N];

void PrintInterface()
{
   
    printf("|------------------------------------|\n"); //28 grids
    printf("|  Jin's Employee management system  |\n");
    printf("|              Welcome!              |\n");
    printf("|      (Type the number to use)      |\n");
    printf("| ---------------------------------- |\n");
    printf("|   1. Insert employee information   |\n");
    printf("|   ------------------------------   |\n");
    printf("|   2. Update employee information   |\n");
    printf("|   ------------------------------   |\n");
    printf("|   3. Query  employee information   |\n");
    printf("|   ------------------------------   |\n");
    printf("|   4. Delete employee information   |\n");
    printf("|   ------------------------------   |\n");
    printf("|   5. Keyword sorting view          |\n");
    printf("| ---------------------------------- |\n");
    printf("|          (Enter 0 to exit)         |\n");
    printf("|------------------------------------|\n"); //28 grids
}

bool cmp_name(node a, node b)
{
   
    return a.name < b.name;
}

bool cmp_age(node a, node b)
{
   
    return a.age < b.age;
}

bool cmp_wage(node a, node b)
{
   
    return a.wage < b.wage;
}

bool cmp_num(node a, node b)
{
   
    return a.num < b.num;
}

void Insert(node *L)
{
   
    system("cls");
    printf("Please input the employee number, name, gender, unit, age, position, telephone number, salary and address in turn.\n");
    printf("NOTE: ***enter the employee number as 0 to exit the function!***\n");
    printf("NOTE: ***Please do not enter the existing number!***\n");
    node *s, *r, *p; //s用来指向新生成的节点。r始终指向L的终端节点。
    r = L;           //r指向了头节点,此时的头节点是终端节点。
    while (r->next != NULL)
        r = r->next;

    ll x;
    printf("Please enter the employee number:\n");
    while (cin >> x && x)
    {
   
        if (!cnt[x])
            cnt[x] = 1;
        else
        {
   
            cout << "The number already exists, please re-enter!" << endl;
            continue;
        }

        s = new node; //s指向新申请的节点
        cnt_man++;

        s->num = x;
        printf("Please enter the employee name:\n");
        scanf(" %s", s->name);
        printf("Please enter the employee gender:\n");
        scanf(" %s", s->gender);
        printf("Please enter the employee unit:\n");
        scanf(" %s", s->department);
        printf("Please enter the employee age:\n");
        cin >> s->age;
        printf("Please enter the employee position:\n");
        scanf(" %s", s->post);
        printf("Please enter the employee telephone number:\n");
        cin >> s->telephone;
        printf("Please enter the employee salary:\n");
        cin >> s->wage;
        printf("Please enter the employee address:\n");
        scanf(" %s", s->site);

        r->next = s; //用r来接纳新节点
        r = s;       //r指向终端节点
        printf("\n");
        printf("Please enter the employee number of the next employee:\n");
    }
    r->next = NULL; //元素已经全部装入链表L中
                    //L的终端节点指针域为NULL,L建立完成
}

void Update(node *L)
{
   
    /*      备用
    char nm[15]; //姓名
    char dp[18]; //单位
    char gd[20]; //性别
    char pt[20]; //职务
    char st[20]; //住址
    int ag;      //年龄
    ll tp;       //电话
    ll wg;       //工资
    */

    ll x; //职工号
CHOOSE3:
    system("cls");
    printf("Enter the employee number of the employee you want to modify:\n");
    cin >> x;

    int flag = 0; //是否找到该员工

    node *p = L->next;
    if (cnt_man == 0)
    {
   
        printf("No employee information, please input first.\n");
    }
    else
    {
   
        while (p != NULL)
        {
   
            if (p->num == x)
            {
   
                flag = 1;
            CHOOSE2:
                int type;
                printf("1. name\n");
                printf("2. unit\n");
                printf("3. gender\n");
                printf("4. position\n");
                printf("5. address\n");
                printf("6. age\n");
                printf("7. telephone\n");
                printf("8. wage\n");
                printf("Select the information you want to modify:\n");
            CHOOSE1:
                cin >> type;
                if (type == 1)
                {
   
                    cout << "The employee's current name: " << p->name << endl;
                    cout << "Revised as: ";
                    cin >> p->name;
                    cout << endl;
                }
                else if (type == 2)
                {
   
                    cout << "The employee's current unit: " << p->department << endl;
                    cout << "Revised as: ";
                    cin >> p->department;
                    cout << endl;
                }
                else if (type == 3)
                {
   
                    cout << "The employee's current gender: " << p->gender << endl;
                    cout << "Revised as: ";
                    cin >> p->gender;
                    cout << endl;
                }
                else if (type == 4)
                {
   
                    cout << "The employee's current position: " << p->post << endl;
                    cout << "Revised as: ";
                    cin >> p->post;
                    cout << endl;
                }
                else if (type == 5)
                {
   
                    cout << "The employee's current address: " << p->site << endl;
                    cout << "Revised as: ";
                    cin >> p->site;
                    cout << endl;
                }
                else if (type == 6)
                {
   
                    cout << "The employee's current age " << p->age << endl;
                    cout << "Revised as: ";
                    cin >> p->age;
                    cout << endl;
                }
                else if (type == 7)
                {
   
                    cout << "The employee's current telepone: " << p->telephone << endl;
                    cout << "Revised as: ";
                    cin >> p->telephone;
                    cout << endl;
                }
                else if (type == 8)
                {
   
                    cout << "The employee's current wage: " << p->wage << endl;
                    cout << "Revised as: ";
                    cin >> p->wage;
                    cout << endl;
                }
                else
                {
   
                    printf("Illegal input! Please enter 1~8 to select!\n");
                    goto CHOOSE1;
                }

                system("cls");

                cout << "Successfully modified, enter 0 to continue to modify this employee information." << endl;
                cout << "Enter - 1 to select other employees for information modification." << endl;
                cout << "Enter - 2 to return to the main interface." << endl;
                int val;
            CHOOSE4:
                cin >> val;
                if (val == 0)
                {
   
                    system("cls");
                    goto CHOOSE2;
                }
                else if (val == -1)
                {
   
                    goto CHOOSE3;
                }
                else if (val == -2)
                {
   
                    break;
                }
                else
                {
   
                    printf("Illegal input! Please enter -2~0 to select!\n");
                    goto CHOOSE4;
                }
            }
            p = p->next;
        }
        if (flag == 0)
        {
   
            printf("The employee was not found! Enter 1 to reselect\n");
            printf("Other inputs return to the main interface\n");
            int vall;
            cin >> vall;
            if (vall == 1)
            {
   
                goto CHOOSE3;
            }
        }
    }
    system("pause");
    printf("\n");
}

void Query(node *L)
{
   
    system("cls");
    if (cnt_man == 0)
    {
   
        printf("No employee information, please input first.\n");
        system("pause");
    }
    else
    {
   
        printf("Input 1 for precise query and 2 for fuzzy query.\n");
        int val;
        cin >> val;
        if (val == 1)
        {
   
        JINGQUE:
            printf("Please enter employee number: ");
            ll nu;
            int flag = 0;
            cin >> nu;
            node *p = L->next;
            while (p != NULL)
            {
   
                if (p->num == nu)
                {
   
                    flag = 1;
                    printf("Employee number: %lld\n", p->num);
                    printf("Name: %s\n", p->name);
                    printf("Age: %lld\n", p->age);
                    printf("Gender: %s\n", p->gender);
                    printf("Department: %s\n", p->department);
                    printf("Post: %s\n", p->post);
                    printf("Site: %s\n", p->site);
                    printf("Telephone: %lld\n", p->telephone);
                    printf("Wage: %lld\n", p->wage);
                    cout << endl;
                    break;
                }
                p = p->next;
            }
            if (flag == 0)
            {
   
                printf("Sorry, there is no information about this employee.\n");
            }

            cout << "Enter 1 to continue the precise search, and enter 2 to perform the fuzzy search." << endl;
            cout << "Other input will return to the main interface." << endl;
            int val2;
            cin >> val2;
            if (val2 == 1)
            {
   
                goto JINGQUE;
            }
            else if (val2 == 2)
            {
   
                goto FUZZY;
            }
        }
        else
        {
   
        FUZZY:
            system("cls");
            ll str;
            int flag = 0;
            cout << "Only age, number, salary and phone number are supported." << endl;
            cout << "Input: ";
            cin >> str;
            cout << "Here are the employees who match the information you entered:" << endl;
            cout << endl;
            node *p = L->next;
            while (p != NULL)
            {
   
                if (p->age == str || p->num == str || p->telephone == str || p->wage == str)
                {
   
                    flag = 1;
                    printf("Employee number: %lld\n", p->num);
                    printf("Name: %s\n", p->name);
                    printf("Age: %lld\n", p->age);
                    printf("Gender: %s\n", p->gender);
                    printf("Department: %s\n", p->department);
                    printf("Post: %s\n", p->post);
                    printf("Site: %s\n", p->site);
                    printf("Telephone: %lld\n", p->telephone);
                    printf("Wage: %lld\n", p->wage);
                    cout << endl;
                }
                p = p->next;
            }
            if (flag == 0)
            {
   
                printf("Sorry, there is no information about this employee.\n");
            }

            cout << "Enter 1 to continue the fuzzy search." << endl;
            cout << "Other input will return to the main interface." << endl;
            int vall;
            cin >> vall;
            if (vall == 1)
                goto FUZZY;
        }
    }
    printf("\n");
}

void Delete(node *L)
{
   
    system("cls");
    if (cnt_man == 0)
    {
   
        printf("No employee information, please input first.\n");
        system("pause");
    }
    else
    {
   
        cout << "Enter 1 to delete by name (note that doing so will delete all employees with the same name!)" << endl;
        cout << "Enter 2 to delete by employee number." << endl;
        int val;
        cin >> val;
        if (val == 1)
        {
   
        NAME:
            int flag = 0;
            char nm[20];
            cout << "Please enter employee name." << endl;
            scanf(" %s", nm);
            node *p = L->next;
            node *pre = L;
            while (p != NULL)
            {
   
                if (strcmp(p->name, nm) == 0)
                {
   
                    flag = 1;
                    cnt[p->num] = 0;
                    pre->next = p->next;
                    node *t = p;
                    p = p->next;
                    free(t);
                    cnt_man--;
                    pre = pre->next;
                    continue;
                }
                pre = pre->next;
                p = p->next;
            }
            if 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值