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

宜宾建设招标网站企业网站建设长沙

宜宾建设招标网站,企业网站建设长沙,微信答题小程序制作,宝安印刷网站建设1. 单链表任意位置删除, 单链表任意位置修改, 单链表任意位置查找, 单链表任意元素查找, 单链表任意元素修改, 单链表任意元素删除, 单链表逆置 // main.c#include head.hint main(int argc, const char *argv[]) {Linklist headNULL; //head 是头指针// printf(head.hint main(int argc, const char *argv[]) {Linklist headNULL; //head 是头指针// printf(head%p\n, head);// printf(head-data%d\n, head-data);// printf(head-next%p\n, head-next);int n;int pos;int key;data_type element;printf(please input n:);scanf(%d, n);for(int i0; in; i){printf(please input No.%d element: , i1);scanf(%d, element);headinsert_head(element, head);}puts(---ouput Linklist---);output(head);/*puts(---get tail node---);Linklist node_tail get_tail_node(head);printf(tail-data%d\n, node_tail-data);puts(---append element---);printf(please input element to append:);scanf(%d, element);headappend(head, element);output(head);puts(---delete first node---);headdelete_first(head);headdelete_first(head);output(head);puts(---delete tail node---);headdelete_tail(head);headdelete_tail(head);output(head);puts(---get list len---);int lenget_len(head);printf(len%d\n, len);puts(---insert_by_pos---);int pos;printf(please input pos: );scanf(%d, pos);printf(please input element: );scanf(%d, element);headinsert_by_pos(head, pos, element);output(head);puts(---get node by pos---);printf(please input pos:);scanf(%d, pos);Linklist node get_node_by_pos(head, pos);printf(node-data%d\n, node-data);*/puts(---delete node by pos---);printf(please input pos:);scanf(%d, pos);head delete_by_pos(head, pos);output(head);puts(---update node by pos---);printf(please input pos:);scanf(%d, pos);printf(please element:);scanf(%d, element);int ret update_by_pos(head, pos, element);output(head);puts(---get node by element---);printf(please element:);scanf(%d, element);pos get_node_by_element(head, element);printf(pos%d\n,pos); //puts(---update node by element---);printf(please input a key:);scanf(%d, key);printf(please input an element:);scanf(%d, element);ret update_node_by_element(head, key, element);output(head); //puts(---delete by element---);printf(please input element:);scanf(%d, element);head delete_node_by_element(head, element);output(head);//puts(---reverse list---);head revser_list(head);output(head); //return 0; }//head.h#ifndef __HEAD_H__ #define __HEAD_H__#include string.h #include stdlib.h #include stdio.htypedef int data_type;typedef struct Node {int data;struct Node *next;}*Linklist;Linklist create();typedef struct Node node;Linklist create_node(); Linklist insert_head(data_type data, Linklist head); int output(Linklist head); Linklist append(Linklist head, data_type element); Linklist get_tail_node(Linklist head); Linklist delete_first(Linklist head); Linklist free_node(Linklist node); Linklist delete_tail(Linklist head); int get_len(Linklist head); Linklist insert_by_pos(Linklist head, int pos, data_type element); Linklist delete_by_pos(Linklist head, int pos); Linklist get_node_by_pos(Linklist head, int pos); int update_by_pos(Linklist head, int pos, data_type element); int get_node_by_element(Linklist head, data_type key); Linklist delete_node_by_element(Linklist head, data_type key); Linklist revser_list(Linklist head); int update_node_by_element(Linklist head, data_type key, data_type element); #endif//test.c#include head.hLinklist create_node() {Linklist node(Linklist)malloc(sizeof(struct Node));if(NULLnode){return NULL;}//successnode-data0;node-nextNULL;return node; }Linklist insert_head(data_type element, Linklist head) {//创建新节点Linklist node create_node();if(NULLnode){return head;}node-dataelement;//判断链表是否位空if(NULLhead){headnode;}else //链表不为空{node-nexthead;headnode; }return head;// 这里的head是形参所以需要返回用以改变主函数的head }int output(Linklist head) {if(NULLhead){return -1;}Linklist node head;while(node!NULL){//printf(data%d, next%p\t, node-data, node-next);printf(%d\t, node-data);nodenode-next;}putchar(10);}Linklist get_tail_node(Linklist head) {Linklist nodehead;while(node-next!NULL node!NULL){nodenode-next;}return node;}Linklist append(Linklist head, data_type element) {//Linklist node create_node();if(NULLnode){return head;}node-dataelement;node-nextNULL;Linklist node_tailget_tail_node(head);if(NULLnode_tail){head node;}node_tail-next node; return head;}Linklist free_node(Linklist node) {free(node);nodeNULL;return node;}Linklist delete_first(Linklist head) {if(NULLhead){return head;}Linklist node_deleted head;headhead-next;node_deleted free_node(node_deleted);return head;}Linklist delete_tail(Linklist head) {if(NULLhead){return head;}//找到 tail 之前的nodeLinklist node head;if(node-nextNULL){headfree_node(node);return head;}while(NULL!node-next-next){nodenode-next;}node-nextfree_node(node-next);node-nextNULL;return head; }int get_len(Linklist head) {//puts(in get_len);int count0;Linklist nodehead;while(node!NULL){//printf(len%d\n, len);count;nodenode-next;}return count;}Linklist insert_by_pos(Linklist head, int pos, data_type element) {//pos, Linklist pos start from 1 hearint lenget_len(head);if(pos1 || poslen1){return head;}if(NULLhead || pos1)headinsert_head(element, head);else{//find node at posLinklist nodehead;for(int i1; ipos-1; i){nodenode-next;}printf(node(pos-1)-data%d, node-data);//create new nodeLinklist node_new create_node();if(NULLnode_new){return head;}node_new-dataelement;//insert node_new-nextnode-next;node-nextnode_new;}return head; }Linklist get_node_by_pos(Linklist head,int pos) {if(NULLhead){return head;}int lenget_len(head);if(pos1||poslen){return NULL;}Linklist nodehead;int count1;while(countpos){count;nodenode-next;}return node;}Linklist delete_by_pos(Linklist head,int pos) {//note: list pos start from 1if(NULLhead){return head;}//判断pos合法int lenget_len(head);if(pos1 poslen) {return head;}if(1len || 1pos){headdelete_first(head);}else{Linklist node get_node_by_pos(head, pos-1);//deleteLinklist node_tbd node-next;node-nextnode-next-next;free_node(node_tbd);node_tbdNULL;}return head;}int update_by_pos(Linklist head, int pos, data_type element) {if(NULLhead){return -1;}Linklist node get_node_by_pos(head, pos);if(NULLnode)return -1;node-dataelement;return 0;}int get_node_by_element(Linklist head, data_type key) {//找到返回pos信息if(NULLhead){return -1;}int count0;int is_found0;Linklist nodehead;while(NULL!node){//printf(node-data%d\n, node-data);count;if(node-datakey){is_found1;break;}nodenode-next;}if(is_found1){return count;}else{return -1;} }Linklist delete_node_by_element(Linklist head, data_type key) {if(NULLhead){return head;}int pos get_node_by_element(head, key);if(-1pos){return head;}headdelete_by_pos(head, pos);return head;}Linklist revser_list(Linklist head) {if(NULLhead||NULLhead-next){return head;}Linklist nodehead-next;head-nextNULL;while(NULL!node){Linklist node_tnode;nodenode-next;node_t-nexthead;headnode_t;}return head; }int update_node_by_element(Linklist head, data_type key, data_type element) {if(NULLhead){return -1;}int posget_node_by_element(head, key);if(-1pos){return -1;}int retupdate_by_pos(head, pos, element);return ret;}运行结果 please input n:7 please input No.1 element: 1 please input No.2 element: 2 please input No.3 element: 3 please input No.4 element: 4 please input No.5 element: 5 please input No.6 element: 6 please input No.7 element: 7 ---ouput Linklist--- 7 6 5 4 3 2 1 ---delete node by pos--- please input pos:1 6 5 4 3 2 1 ---update node by pos--- please input pos:2 please element:500 6 500 4 3 2 1 ---get node by element--- please element:4 pos3 ---update node by element--- please input a key:4 please input an element:400 6 500 400 3 2 1 ---delete by element--- please input element:2 6 500 400 3 1 ---reverse list--- 1 3 400 500 6 2.思维导图
http://www.hkea.cn/news/14318504/

相关文章:

  • 上海工程建设招投标网站国内免费自建网站
  • 最流行的网站开发语言wordpress图片0x0
  • 贵州三蒲建设工程有限公司网站国外服务器网站
  • 深圳建设个网站甜品网站设计与实现毕业设计
  • 如何通过做网站赚钱网站改版完成
  • 有关做洁净工程的企业网站百度推广官方投诉电话
  • 物业管理 网站开发西宁网站优化
  • 广西网站设计欣赏烟台做网站找哪家好
  • 主备网站服务器自动切换 win2003国外免费网站域名服务器入口
  • 网站白名单查询公司做网站的费用记什么科目
  • 护肤品网站建设的摘要学者网学科建设网站
  • 网站怎么添加背景移动网站开发 书
  • 网建设门户网站网站建设 力洋网络
  • 墙蛙网站谁家做的企业logo设计方案
  • 重庆建设工程信息网官网二级建造师注册信息查询南宁网站推广优化
  • 绍兴网站建设网站企业网站软件下载
  • 西安免费做网站微信的公众平台网站开发
  • 会宁网站建设域名备案查询系统工信部
  • 广州代做网站软件开发前景和收入
  • 做偏门网站餐饮品牌设计公司哪家好
  • 网站分页代码二手书的网站建设
  • 南宁企业做网站做家装的网站有哪些
  • 网站访问量排行榜wordpress 获取文章时间
  • 网站建设与维护要用到代码吗建设银行洛阳市分行网站
  • SEO网站价格开发公司正式电未接通
  • 农安建设局网站全网营销推广平台
  • 广州网站建设推荐q479185700霸屏大型搜索网站开发
  • wordpress 一栏广西seo网站
  • 什么是网站主办者python基础教程电子书百度网盘
  • 做网站运营的要求专业外贸网站