当前位置: 首页 > wzjs >正文

海淀网站建设联系方式专业做网站建设公司有哪些

海淀网站建设联系方式,专业做网站建设公司有哪些,专题网站建设意义何在,有了域名之后如何做网站链表 链表是一种线性数据结构,其中元素不是存储在连续的内存位置,而是通过指针链接在一起。每个元素称为一个节点,包含数据部分和指向下一个节点的指针。 单向链表示例: 假设有一个链表包含三个节点:1 -> 2 ->…

链表

链表是一种线性数据结构,其中元素不是存储在连续的内存位置,而是通过指针链接在一起。每个元素称为一个节点,包含数据部分和指向下一个节点的指针。

单向链表示例:

假设有一个链表包含三个节点:1 -> 2 -> 3 -> NULL

单向链表的C语言实现

#include <stdio.h>
#include <stdlib.h>// 定义链表节点结构
struct Node {int data;           // 数据部分struct Node* next;  // 指向下一个节点的指针
};// 创建新节点
struct Node* createNode(int data) {struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));if (!newNode) {printf("内存分配失败\n");exit(1);}newNode->data = data;newNode->next = NULL;return newNode;
}// 在链表头部插入节点
void insertAtHead(struct Node** head, int data) {struct Node* newNode = createNode(data);  // 创建新节点newNode->next = *head;                  // 新节点指向原来的头节点*head = newNode;                        // 更新头节点为新节点
}// 打印链表
void printList(struct Node* head) {struct Node* current = head;while (current != NULL) {printf("%d -> ", current->data);     // 打印当前节点的数据current = current->next;            // 移动到下一个节点}printf("NULL\n");                       // 表示链表结束
}int main() {struct Node* head = NULL;insertAtHead(&head, 3);                 // 插入节点3insertAtHead(&head, 2);                 // 插入节点2insertAtHead(&head, 1);                 // 插入节点1printf("链表: ");printList(head);// 记得释放内存struct Node* temp;while (head != NULL) {temp = head;head = head->next;free(temp);}return 0;
}

栈(基于链表)

栈是一种后进先出(LIFO)的数据结构。我们可以使用链表来实现栈,其中链表的头部作为栈顶。

栈示例:

假设有一个栈包含三个元素:10 -> 20 -> 30 (30是栈顶)

基于链表的栈的C语言实现

#include <stdio.h>
#include <stdlib.h>// 定义栈节点结构
struct StackNode {int data;           // 数据部分struct StackNode* next;  // 指向下一个节点的指针
};// 创建新节点
struct StackNode* createStackNode(int data) {struct StackNode* newNode = (struct StackNode*)malloc(sizeof(struct StackNode));if (!newNode) {printf("内存分配失败\n");exit(1);}newNode->data = data;newNode->next = NULL;return newNode;
}// 检查栈是否为空
int isEmpty(struct StackNode* root) {return !root;
}// 入栈操作
void push(struct StackNode** root, int data) {struct StackNode* stackNode = createStackNode(data);  // 创建新节点stackNode->next = *root;                              // 新节点指向原来的栈顶*root = stackNode;                                    // 更新栈顶为新节点printf("%d 已入栈\n", data);
}// 出栈操作
int pop(struct StackNode** root) {if (isEmpty(*root)) {printf("栈为空\n");return -1; // 返回一个特殊值表示错误}struct StackNode* temp = *root;*root = (*root)->next;                                // 更新栈顶为下一个节点int popped = temp->data;free(temp);                                             // 释放已弹出节点的内存return popped;
}// 获取栈顶元素
int peek(struct StackNode* root) {if (isEmpty(root)) {printf("栈为空\n");return -1; // 返回一个特殊值表示错误}return root->data;
}int main() {struct StackNode* root = NULL;push(&root, 10);                                      // 入栈10push(&root, 20);                                      // 入栈20push(&root, 30);                                      // 入栈30printf("栈顶元素是 %d\n", peek(root));                // 查看栈顶元素printf("%d 出栈\n", pop(&root));                      // 出栈30printf("%d 出栈\n", pop(&root));                      // 出栈20printf("%d 出栈\n", pop(&root));                      // 出栈10// 记得释放内存while (!isEmpty(root)) {pop(&root);}return 0;
}

树是一种非线性的数据结构,由节点组成,其中每个节点都有零个或多个子节点。根节点没有父节点,而其他每个节点恰好有一个父节点。

二叉搜索树示例:

假设有一棵二叉搜索树包含三个节点:5 -> (3, 7)

二叉搜索树的C语言实现

#include <stdio.h>
#include <stdlib.h>// 定义树节点结构
struct TreeNode {int data;               // 数据部分struct TreeNode* left;  // 指向左子节点的指针struct TreeNode* right; // 指向右子节点的指针
};// 创建新节点
struct TreeNode* createTreeNode(int data) {struct TreeNode* newNode = (struct TreeNode*)malloc(sizeof(struct TreeNode));if (!newNode) {printf("内存分配失败\n");exit(1);}newNode->data = data;newNode->left = NULL;newNode->right = NULL;return newNode;
}// 插入节点到二叉搜索树
struct TreeNode* insertBST(struct TreeNode* node, int data) {if (node == NULL) {return createTreeNode(data);  // 如果节点为空,则创建新节点}if (data < node->data) {node->left = insertBST(node->left, data);   // 插入左子树} else if (data > node->data) {node->right = insertBST(node->right, data); // 插入右子树}return node;
}// 中序遍历二叉搜索树
void inorderTraversal(struct TreeNode* node) {if (node != NULL) {inorderTraversal(node->left);               // 遍历左子树printf("%d -> ", node->data);             // 打印当前节点的数据inorderTraversal(node->right);              // 遍历右子树}
}int main() {struct TreeNode* root = NULL;root = insertBST(root, 5);                    // 插入节点5insertBST(root, 3);                           // 插入节点3insertBST(root, 7);                           // 插入节点7printf("中序遍历结果: ");inorderTraversal(root);printf("NULL\n");// 记得释放内存// 这里为了简化,省略了具体的内存释放代码return 0;
}

图是一种非线性的数据结构,由一组节点(也称为顶点)及其之间的连接(边)组成。图可以是有向的也可以是无向的。

无向图(邻接表表示法)示例:

假设有一个无向图包含五个顶点和六条边:0-1, 0-4, 1-2, 1-3, 1-4, 2-3, 3-4

邻接表表示的无向图的C语言实现

#include <stdio.h>
#include <stdlib.h>// 定义邻接表节点
struct AdjListNode {int dest;                   // 目标顶点struct AdjListNode* next;   // 指向下一条边
};// 定义邻接表
struct AdjList {struct AdjListNode* head;   // 邻接表的头节点
};// 定义图
struct Graph {int V;                      // 顶点数量struct AdjList* array;      // 邻接表数组
};// 创建邻接表节点
struct AdjListNode* newAdjListNode(int dest) {struct AdjListNode* newNode = (struct AdjListNode*)malloc(sizeof(struct AdjListNode));newNode->dest = dest;newNode->next = NULL;return newNode;
}// 创建图
struct Graph* createGraph(int V) {struct Graph* graph = (struct Graph*)malloc(sizeof(struct Graph));graph->V = V;// 创建邻接表数组graph->array = (struct AdjList*)malloc(V * sizeof(struct AdjList));// 初始化每个邻接列表为空for (int i = 0; i < V; ++i)graph->array[i].head = NULL;return graph;
}// 添加边到图中
void addEdge(struct Graph* graph, int src, int dest) {// 添加一条从src到dest的边struct AdjListNode* newNode = newAdjListNode(dest);newNode->next = graph->array[src].head;graph->array[src].head = newNode;// 由于是无向图,再添加一条从dest到src的边newNode = newAdjListNode(src);newNode->next = graph->array[dest].head;graph->array[dest].head = newNode;
}// 打印图
void printGraph(struct Graph* graph) {for (int v = 0; v < graph->V; ++v) {struct AdjListNode* pCrawl = graph->array[v].head;printf("\n顶点 %d 的邻居:\n 头 ", v);while (pCrawl) {printf("-> %d", pCrawl->dest);pCrawl = pCrawl->next;}printf("\n");}
}int main() {// 创建一个包含5个顶点的图int V = 5;struct Graph* graph = createGraph(V);addEdge(graph, 0, 1);                         // 添加边0-1addEdge(graph, 0, 4);                         // 添加边0-4addEdge(graph, 1, 2);                         // 添加边1-2addEdge(graph, 1, 3);                         // 添加边1-3addEdge(graph, 1, 4);                         // 添加边1-4addEdge(graph, 2, 3);                         // 添加边2-3addEdge(graph, 3, 4);                         // 添加边3-4// 打印图的内容printGraph(graph);// 记得释放内存for (int i = 0; i < V; ++i) {struct AdjListNode* adjListPtr = graph->array[i].head;while (adjListPtr) {struct AdjListNode* tmp = adjListPtr;adjListPtr = adjListPtr->next;free(tmp);}}free(graph->array);free(graph);return 0;
}

文章转载自:

http://BTz0TyO2.jLthz.cn
http://AXwTlEm7.jLthz.cn
http://9EBC1f8b.jLthz.cn
http://rEQWOCG7.jLthz.cn
http://m3FqnH3f.jLthz.cn
http://A0gKmwB7.jLthz.cn
http://gXB7hrQj.jLthz.cn
http://vv5PfcM0.jLthz.cn
http://9d5e6IqS.jLthz.cn
http://8lOtHGYD.jLthz.cn
http://vm2Kslwm.jLthz.cn
http://zZkLpQO3.jLthz.cn
http://JsGLRHkW.jLthz.cn
http://JXjjGlme.jLthz.cn
http://SwZtPzbs.jLthz.cn
http://Qflosvvi.jLthz.cn
http://B0Loa1jT.jLthz.cn
http://h0jwZ5Fh.jLthz.cn
http://IiCvixzZ.jLthz.cn
http://tJuLKTYF.jLthz.cn
http://LpvrfGGu.jLthz.cn
http://iG33Ze3y.jLthz.cn
http://A4pVGlBm.jLthz.cn
http://HeAHCYYq.jLthz.cn
http://71GTjKC7.jLthz.cn
http://FfwpPE6l.jLthz.cn
http://ZYDkLh67.jLthz.cn
http://kqcka4g2.jLthz.cn
http://u896zvpi.jLthz.cn
http://oqjWA6af.jLthz.cn
http://www.dtcms.com/wzjs/758958.html

相关文章:

  • 个人如何优化网站有哪些方法南京网站开发南京乐识权威
  • 延安市建设厅网站宁津网页设计
  • 叫别人做网站后怎么更改密码做网站的网页设计用cdr吗
  • 药品在网站上做标签有哪些分类孵化基地网站怎么建设
  • 网站开发过程有几个阶段会计公司网站样式
  • 网站运营管理方案网站开发有几种语言
  • 南昌网站建设志博谷歌外贸网站建站
  • 招聘网站建设公司wordpress主题代码编辑教程
  • 开平网站建设汕头有没有做网站
  • 阿里云做的网站程序小型办公室装修
  • 外贸网站设计模板汽车租赁网站建设内容
  • 客户要做网站建设话术梅州建站怎么做
  • 长沙企业建站公司wordpress同步微信素材
  • 网站建设公司与前端莱芜app下载
  • 专业做网站平台淘宝买模板注浆做网站
  • 浙江金圣建设有限公司网站如何学做网站
  • 南昌网站建设公司烟台品牌网站建设
  • 如何开发微网站网站建设数据的保密性
  • 合肥网站建设 合肥网络推广青岛网站建设订做
  • 端子网站建设ue4培训班一般学费多少
  • 防城港网站建设太原网站建站模板
  • 三明网站设计建网站要多少钱一台
  • 沂水网站开发深圳网站建设网页推广网站设计
  • h5动画网站旅游网站建设规划方案
  • 2023年最新科技新闻摘抄分站城市网站如何做seo
  • 常德网站建设字答科技jsp网站开发源码实例
  • 如何做后台管理员网站苏州有什么好玩的景点
  • 怎么安装网站代码wordpress企业网站开发
  • app开发导入网站模板建公司网站步骤
  • 国内投资咨询网站 html模板前端网站开发课程