数据结构考试大纲要求

/**
单链表的有关操作(Shubao Lv)
⑴随机产生或键盘输入一组元素,建立一个带头结点的单向链表(无序)。
⑵遍历单向链表。
⑶把单向链表中元素逆置(不允许申请新的结点空间)。
⑽在主函数中设计一个简单的菜单,分别调试上述算法。

*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <malloc.h>
using namespace std;
struct note
{
    int num;
    note *next;
};
note *h;
///建立单链表
void creatLink()
{
    printf("输入0结束(第一个数不能为0)\n");
    note *p1,*p2;
    p1=(struct note *)malloc(sizeof(struct note));
    h=NULL;
    p1->next=NULL;
    scanf("%d",&p1->num);
    h=p1;
    p2=p1;
    p1=(struct note *)malloc(sizeof(struct note));
    p2->next=p1;
    int x;
       scanf("%d",&x);
    while(x)
    {
        p1->num=x;
        p2=p1;
        p1=(struct note *)malloc(sizeof(struct note));
        p2->next=p1;
        scanf("%d",&x);
    }
    p2->next=NULL;
}
///遍历单链表
void bianli()
{
    note *p;
    for(p=h;p!=NULL;p=p->next)
        printf("%d ",p->num);
    puts("");
}
///倒置单链表
void daozhi()
{
    note *pre,*cur,*nex;
    pre=h;
    cur=h->next;
    nex=NULL;
    while(cur!=NULL)
    {
        nex=cur->next;
        cur->next=pre;
        pre=cur;
        cur=nex;
    }
    h->next=NULL;
    h=pre;
    bianli();
}
int main()
{
    creatLink();
    /*srand(time(NULL));
    int n=rand()%255+1;*/
    bianli();
    daozhi();
    return 0;
}
 

 

/**
栈和队列的基本操作(Shubao Lv)
⑴采用链式存储实现栈的初始化、入栈、出栈操作。
⑵采用顺序存储实现栈的初始化、入栈、出栈操作。
⑶采用链式存储实现队列的初始化、入队、出队操作。
⑷采用顺序存储实现循环队列的初始化、入队、出队操作。
⑸在主函数中设计一个简单的菜单,分别测试上述算法。
*⑹综合训练:①利用栈实现表达式求值算法。

*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define INIT_SIZE 100
#define INCREASEMENT 10
using namespace std;

const int INF = -0xfffffff;

struct Strack
{
    int *top;///栈顶的指针
    int *base;///栈底的指针
    int stracksize;
    void init()///栈的初始化
    {
        base=(int *) malloc(INIT_SIZE * sizeof(int ));///分配内存
        top=base;
        stracksize = INIT_SIZE;
    }
    int Top() ///返回栈顶元素
    {
        if(top==base)
            return INF;
        return *(top-1);
    }
    bool pop() ///删除栈顶元素
    {
        if(top==base)
            return false;
        top--;
        return true;
    }
    void push(int x) ///栈顶插入元素
    {
        if(top-base>=stracksize) ///如果内存不够重新分配内存
        {
            base=(int *)realloc(base,(stracksize+INCREASEMENT)*(sizeof(int )));
            top=base+stracksize;
            stracksize+=INCREASEMENT;
        }
        *top++=x;
    }
    bool empty() ///判断栈是否为空
    {
        if(top==base)
            return true;
        return false;
    }
}s;
struct Queue
{
    int *top;///队顶的指针
    int *base;///队底的指针
    int queuesize;
    void init()///队的初始化
    {
        base=(int *) malloc(INIT_SIZE * sizeof(int ));///分配内存
        top=base;
        queuesize = INIT_SIZE;
    }
    int Top() ///返回队顶元素
    {
        if(top==base)
            return INF;
        return *top;
    }
    bool pop() ///删除队顶元素
    {
        if(top==base)
            return false;
        top++;
        return true;
    }
    void push(int x) ///队顶插入元素
    {
        if(base-top>=queuesize) ///如果内存不够重新分配内存
        {
            base=(int *)realloc(base,(queuesize+INCREASEMENT)*(sizeof(int )));
            base=top+queuesize;
            queuesize+=INCREASEMENT;
        }
        *base++=x;
    }
    bool empty() ///判断队是否为空
    {
        if(top==base)
            return true;
        return false;
    }
}q;
int main()
{
    ///==============栈的部分================
    int x;
    s.init();
    cout<< "1、进栈:\n(输入要进栈的元素,以0结束)\n";
    while(1)
    {
        int x;
        scanf("%d",&x);
        if(x==0)
            break;
        s.push(x);
    }
    cout<<"出栈:\n";
    while(!s.empty())
    {
        printf("%d ",s.Top());
        s.pop();
    }
    puts("");
    ///============队列的部分================
    q.init();
    cout<< "\n2、入队:\n(输入要入队的元素,以0结束)\n";
    while(1)
    {
        int x;
        scanf("%d",&x);
        if(x==0)
            break;
        q.push(x);
    }
    cout<<"出队:\n";
    while(!q.empty())
    {
        printf("%d ",q.Top());
        q.pop();
    }
    puts("");
    return 0;
}




 

<pre class="cpp" name="code">#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
/**
二叉树的有关操作(Shubao Lv)
⑴输入字符序列,建立二叉链表。
⑵中序遍历二叉树:递归算法。
⑶中序遍历二叉树:非递归算法。(最好也能实现先序,后序非递归算法)
(4)正则二叉树是二叉树中不存在子树个数为一的结点,即节点的度为2.
 判断一棵树是正则二叉树的算法
⑼在主函数中设计一个简单的菜单,分别调试上述算法。

*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define NULL 0
#define N 10
int sum;
struct node
{
    int data;
    node *lchild,*rchild;
};
node *creat_tree()
{
    node *t;
    int x;
    cin >> x;
    if(x!=0)
    {
        t=new node;
        t->data=x;
        t->lchild=creat_tree();
        t->rchild=creat_tree();
    }
    else
        t=NULL;
    return t;
}
///递归先序遍历二叉树
void preorder(node *t)
{
    if(t)
    {
        cout << t->data<<" ";
        preorder(t->lchild);
        preorder(t->rchild);
    }
}

///非递归先序遍历算法
void preorder1(node *t)
{
    node * s[N],*p;
    int top;
    top=0;
    p=t;
    while(p || top>0)
    {
        while(p)
        {
            cout<<p->data<<" ";
            top++;
            s[top]=p;
            p=p->lchild;
        }
        if(top>0)
        {
            p=s[top];
            --top;
            p=p->rchild;
        }
    }
}
///非递归中序遍历二叉树
void inorder(node *t)
{
    node *p,*s[N];
    int top;
    top=0;
    p=t;
    while(p || top>0)
    {
        while(p)
        {
            top++;
            s[top]=p;
            p=p->lchild;
        }
        if(top>0)
        {
            p=s[top];
            top--;
            cout<<p->data<<" ";
            p=p->rchild;
        }
    }
}
///二叉树后根非递归算法
void pasorder1(node *t)
{
    struct
    {
        node *pp;
        int tag;
    } ss[N];
    int top;
    node *p;
    top=0;
    p=t;
    while(p || top>0)
    {
        while(p)
        {
            top++;
            ss[top].tag=0;
            ss[top].pp=p;
            p=p->lchild;
        }
        if(top>0)
            if(ss[top].tag==0)
            {
                ss[top].tag=1;
                p=ss[top].pp;
                p=p->rchild;
            }
            else
            {
                p=ss[top].pp;
                cout<<p->data<<" ";
                top--;
                p=NULL;
            }
    }
}
///递归算法判断是否是正则二叉树
void count_leaf(node *t)
{
    if(t)
    {
        if((t->lchild!=NULL && t->rchild==NULL)||(t->lchild==NULL && t->rchild!=NULL))
            sum=0;
        count_leaf(t->lchild);
        count_leaf(t->rchild);
    }
}
int main()
{
    int num;
    node *t;
    t=creat_tree();
    cout << "前序遍历:\n";
    preorder(t);
    cout <<endl;
    cout << " 中序遍历:\n";
    inorder(t);
    cout <<endl;
    /**pasorder1(t);
    cout <<endl;
    preorder1(t);
    cout <<endl;*/
    cout <<"是否为正则二叉树:\n";
    sum=1;
    count_leaf(t);
    if(sum)
       cout<<"YES\n";
    else
        cout <<"NO\n";
    return 0;
}
/**
1
2
4
0
0
5
0
0
3
6
0
0
7
0
0

1
2
4
0
0
0
3
5
0
0
6
0
0
*/

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据结构》实验教学大纲 数据结构实验 Data Structure Experiment 工学 计算机科学与技术 先修课程:高等数学、离散数学、程序设计基础(C语言 或 C++语言) 课程性质 数据结构是计算机科学的算法理论基础和软件设计的技术基础,是计算机科学技术专业的基础理论课程,是计算机学科的核心课程之一。在计算机科学技术的各个领域,选择合适的数据结构一个重要问题;具备分析算法复杂度、比较算法性能和优化算法的能力是计算机专业学生必须具备的重要专业能力。通过数据结构与算法的学习,能进一步提高软件设计与编写高效程序的能力,提高应用计算机技术解决实际问题的能力。 本课程是结合《数据结构》课堂教学安排的实验与实践课程,它是对学生的一种全面综合训练,是与课堂教学与课后练习,完成程序分析与设计、理论与实践相结合的训练的必不可少的一个教学环节。本实验课程目的是加深对数据结构与算法的理解,加强理论与实践的结合,培养学生的综合动手能力。本实验强调基础知识与实际应用相结合,促使学生掌握知识并应用于解决实际问题,培养学生的动手能力和实践应用能力,起到深化理解和灵活掌握教学内容的目的。 课程任务 进行本课程实验之前,课堂任课教师或实验教师必须要求学生认真复习C语言(或C++语言)的基本编程方法,熟悉编程环境。通过本课程实验,使学生学会和掌握本课程的基本知识点和重点内容,理解数据结构的基本概念和基本原理,深刻理解逻辑结构、存储结构、算法设计之间的关系,掌握分析问题的基本方法,熟练编程的基本方法和技巧,提高解决问题的能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值