再谈数据结构

       小亮今天和去法国读研的大学同学聊了聊,他需要数据结构C语言版本的资料,我就整理了一下,毕竟算法岗位很讲究逻辑的严谨性和规则,数据结构很重要的。详情请见下文!

相关代码参考小亮的CSDN下载地址:https://download.csdn.net/download/jinyuan7708/10648168
这里是小亮的blog地址:https://legendtianjin.github.io/NextLegend.github.io/
笔者信息:Next_Legend QQ:1219154092 机器学习 深度学习 模式识别 自然语言处理 计算机视觉

——2018.9.5于天津大学


一、原由

       小亮的同学(栗同学)在大学和小亮是一个专业的,研究生申请到了法国格勒诺布尔大学,(很优秀哈)。先介绍一下这个大学哈:
       格勒诺布尔大学集团(格勒诺布尔-阿尔卑斯大学)是一所拥有近七百年历史的国立研究型大学,其科研实力处于法国顶尖水平,诞生过两位诺贝尔奖获得者(克劳斯·冯·克利青Klaus von Klitzing

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据结构的Java代码实现时,还有很多其他常见的数据结构可以探索,例如栈、队列、树和图。下面我将进一步介绍这些数据结构的代码实现。 1. 栈(Stack): 栈是一种先进后出(LIFO)的数据结构。以下是使用数组实现栈的简单示例: ```java class Stack { private int maxSize; private int top; private int[] stackArray; public Stack(int size) { maxSize = size; stackArray = new int[maxSize]; top = -1; } public void push(int value) { if (top < maxSize - 1) { stackArray[++top] = value; } } public int pop() { if (top >= 0) { return stackArray[top--]; } return -1; } public int peek() { if (top >= 0) { return stackArray[top]; } return -1; } public boolean isEmpty() { return (top == -1); } } ``` 2. 队列(Queue): 队列是一种先进先出(FIFO)的数据结构。以下是使用数组实现队列的简单示例: ```java class Queue { private int maxSize; private int front; private int rear; private int[] queueArray; public Queue(int size) { maxSize = size; queueArray = new int[maxSize]; front = 0; rear = -1; } public void enqueue(int value) { if (rear < maxSize - 1) { queueArray[++rear] = value; } } public int dequeue() { if (front <= rear) { return queueArray[front++]; } return -1; } public int peek() { if (front <= rear) { return queueArray[front]; } return -1; } public boolean isEmpty() { return (front > rear); } } ``` 3. 树(Tree): 树是一种非线性的数据结构,它由节点组成,每个节点可以有多个子节点。以下是使用链表实现二叉树的简单示例: ```java class TreeNode { int data; TreeNode left; TreeNode right; public TreeNode(int data) { this.data = data; this.left = null; this.right = null; } } class BinaryTree { TreeNode root; public BinaryTree() { root = null; } public void insert(int data) { root = insertNode(root, data); } private TreeNode insertNode(TreeNode root, int data) { if (root == null) { root = new TreeNode(data); return root; } if (data < root.data) { root.left = insertNode(root.left, data); } else if (data > root.data) { root.right = insertNode(root.right, data); } return root; } public void traverseInOrder() { inOrder(root); } private void inOrder(TreeNode root) { if (root != null) { inOrder(root.left); System.out.print(root.data + " "); inOrder(root.right); } } } ``` 4. 图(Graph): 图是一种由节点和边组成的非线性数据结构。以下是使用邻接矩阵表示图的简单示例: ```java class Graph { private int vertexCount; private boolean[][] matrix; public Graph(int vertexCount) { this.vertexCount = vertexCount; matrix = new boolean[vertexCount][vertexCount]; } public void addEdge(int source, int destination) { if (source >= 0 && source < vertexCount && destination >= 0 && destination < vertexCount) { matrix[source][destination] = true; matrix[destination][source] = true; } } public void removeEdge(int source, int destination) { if (source >= 0 && source < vertexCount && destination >= 0 && destination < vertexCount) { matrix[source][destination] = false; matrix[destination][source] = false; } } public boolean hasEdge(int source, int destination) { if (source >= 0 && source < vertexCount && destination >= 0 && destination < vertexCount) { return matrix[source][destination]; } return false; } } ``` 这些是一些常见数据结构的Java代码实现示例。你可以根据需要进行修改和扩展,以满足特定的问题要求。希望这些示例能够帮助你更好地理解数据结构的Java代码实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值