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

贵阳网站建设企业企业解决方案网站

贵阳网站建设企业,企业解决方案网站,odoo与wordpress,潍坊专业做网站的公司目录 链表基本操作 删除重复元素 查找倒数第N个节点 查找中间节点 约瑟夫环 循环链表 合并有序链表 逆置链表 逆置链表(双向链表) 链表基本操作 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail…目录 链表基本操作 删除重复元素  查找倒数第N个节点 查找中间节点 约瑟夫环 循环链表 合并有序链表 逆置链表 逆置链表(双向链表) 链表基本操作 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned char elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned char elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(void) {struct node *p;for(p head; p; p p-next)printf(%c, p-elem);printf(\n); }int search(unsigned char elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hstruct node {unsigned char elem;struct node *next; };void create_list(unsigned char elem); void insert_node(int pos, unsigned char elem); void delete_node(int pos); void print_linklist(void); int search(unsigned char elem);#endif //main.c#include stdio.h #include linklist.hint main(void) {create_list(A);create_list(B);create_list(C);create_list(D);print_linklist();delete_node(0);print_linklist();insert_node(0, F);insert_node(2, Z);print_linklist();if(search(C))printf(the elem is found in the linklist\n);elseprintf(Can not find it\n);return 0; }删除重复元素  //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(struct node *linklist_head) {struct node *p;for(p linklist_head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }void delete_repeat(struct node *head) {int flag[10] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};struct node *p head;struct node *q NULL;flag[p-elem] 1;while(p-next ! NULL){if(flag[p-next-elem] 0){flag[p-next-elem] 1;p p-next;}else{q p-next;p-next q-next;free(q);}} }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(struct node *linklist_head); int search(unsigned int elem); void delete_repeat(struct node *head);#endif //main.c#include stdio.h #include linklist.hint main(void) {create_list(1);create_list(2);create_list(8);create_list(2);create_list(3);create_list(9);create_list(4);create_list(6);create_list(4);create_list(8);create_list(7);create_list(5);create_list(2);create_list(9);create_list(6);print_linklist(head);delete_repeat(head);print_linklist(head);return 0; }查找倒数第N个节点 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(struct node *linklist_head) {struct node *p;for(p linklist_head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }int find_mid(struct node *linklist_head) {struct node *p;struct node *q;p q linklist_head;while(p ! NULL p-next ! NULL){p p-next-next;q q-next;}return q-elem; }int find_last_nth(struct node *linklist_head, int n) {int i;struct node *p;struct node *q;p q linklist_head;for(i 0; i n-1; i)p p-next;while(p-next ! NULL){p p-next;q q-next;}return q-elem; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(struct node *linklist_head); int search(unsigned int elem); int find_mid(struct node *linklist_head); int find_last_nth(struct node *linklist_head, int n);#endif //main.c#include stdio.h #include linklist.hint main(void) {int n;create_list(1);create_list(2);create_list(3);create_list(4);create_list(5);create_list(6);create_list(7);create_list(8);create_list(9);create_list(10);print_linklist(head);printf(Please enter the last one you want to show:);scanf(%d, n);printf(the last n :%d\n, find_last_nth(head, n));return 0; }查找中间节点 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(struct node *linklist_head) {struct node *p;for(p linklist_head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }int find_mid(struct node *linklist_head) {struct node *p;struct node *q;p q linklist_head;while(p ! NULL p-next ! NULL){p p-next-next;q q-next;}return q-elem; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(struct node *linklist_head); int search(unsigned int elem); int find_mid(struct node *linklist_head);#endif //main.c#include stdio.h #include linklist.hint main(void) {create_list(1);create_list(2);create_list(3);create_list(4);create_list(5);create_list(6);create_list(7);create_list(8);create_list(9);create_list(10);print_linklist(head);printf(mid %d\n, find_mid(head));return 0; }约瑟夫环 约瑟夫问题是个著名的问题N个人围成一圈第一个人从1开始报数报M的将被杀掉下一个人接着从1开始报。如此反复最后剩下一个求最后的胜利者。 例如只有三个人把他们叫做A、B、C他们围成一圈从A开始报数假设报2的人被杀掉。 ●首先A开始报数他报1。侥幸逃过一劫。 ●然后轮到B报数他报2。非常惨他被杀了 ●C接着从1开始报数 ●接着轮到A报数他报2。也被杀死了。 ●最终胜利者是C //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p;tail-next head; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;tail-next head;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next head)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);tail-next head;}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next head)tail pre;free(p);} }void print_linklist(void) {struct node *p;p head;// for(p head; p ! head; p p-next) // printf(%d, p-elem);do{printf(%5d, p-elem);p p-next;}while(p ! head);printf(\n); }int search(unsigned int elem) {struct node *p;p head;// for(p head; p; p p-next) // if(p-elem elem) // return 1;do{if(p-elem elem)return 1;p p-next;}while(p ! head);return 0; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(void); int search(unsigned int elem);#endif //main.c#include stdio.h #include linklist.h #include stdlib.hint main(void) {int n, k, m;int i;struct node *p, *q;printf(Please enter the number of person:);scanf(%d, n);for(i 1; i n; i)create_list(i);print_linklist();p head;printf(Please enter the start num:);scanf(%d, k);while(--k)p p-next; // printf(p-elem %d\n, p-elem);printf(Please enter the m:);scanf(%d, m);if(1 m){for(i 0; i n; i){printf(%3d, p-elem);p p-next;}printf(\n);}else{while(n--){for(i 1; i m - 1; i)p p-next;q p;p p-next;printf(%3d, p-elem);q-next p-next;free(p);p p-next;}printf(\n);}return 0; }循环链表 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p;tail-next head; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;tail-next head;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next head)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);tail-next head;}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next head)tail pre;free(p);} }void print_linklist(void) {struct node *p;p head;// for(p head; p ! head; p p-next) // printf(%d, p-elem);do{printf(%5d, p-elem);p p-next;}while(p ! head);printf(\n); }int search(unsigned int elem) {struct node *p;p head;// for(p head; p; p p-next) // if(p-elem elem) // return 1;do{if(p-elem elem)return 1;p p-next;}while(p ! head);return 0; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hstruct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(void); int search(unsigned int elem);#endif //main.c#include stdio.h #include linklist.hint main(void) {create_list(1);create_list(2);create_list(3);create_list(4);create_list(5);create_list(6);create_list(7);print_linklist();insert_node(0, 11);print_linklist();delete_node(6);print_linklist();delete_node(0);print_linklist();delete_node(0);print_linklist();delete_node(4);print_linklist();insert_node(0, 8);print_linklist();insert_node(5, 9);print_linklist();insert_node(2, 13);print_linklist();return 0; }合并有序链表 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(struct node *linklist_head) {struct node *p;for(p linklist_head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(struct node *linklist_head); int search(unsigned int elem);#endif //main.c#include stdio.h #include linklist.hint main(void) {struct node *head1 NULL;struct node *head2 NULL;struct node *p NULL; //head1struct node *q NULL; //head2create_list(1);create_list(9);create_list(13);create_list(27);head1 head;print_linklist(head1);head NULL;create_list(3);create_list(5);create_list(14);create_list(81);create_list(88);create_list(95);create_list(99);head2 head;print_linklist(head2);head NULL;p head1;q head2;while(p q){if(p-elem q-elem){if(head NULL)head p;elsetail-next p;tail p;p p-next;}else{if(head NULL)head q;elsetail-next q;tail q;q q-next;}}tail-next p?p:q;print_linklist(head);return 0; }逆置链表 //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-next NULL;if(head NULL)head p;elsetail-next p;tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-next pre-next;pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next NULL)tail pre;free(p);} }void print_linklist(struct node *linklist_head) {struct node *p;for(p linklist_head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }int find_mid(struct node *linklist_head) {struct node *p;struct node *q;p q linklist_head;while(p ! NULL p-next ! NULL){p p-next-next;q q-next;}return q-elem; }int find_last_nth(struct node *linklist_head, int n) {int i;struct node *p;struct node *q;p q linklist_head;for(i 0; i n-1; i)p p-next;while(p-next ! NULL){p p-next;q q-next;}return q-elem; }void reverse_linklist(struct node *linklist_head) {struct node *p, *n;p linklist_head-next;linklist_head-next NULL;while(p-next ! NULL){n p-next;p-next linklist_head;linklist_head p;p n;}p-next linklist_head;linklist_head p;head linklist_head; }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hextern struct node *head; extern struct node *tail;struct node {unsigned int elem;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(struct node *linklist_head); int search(unsigned int elem); int find_mid(struct node *linklist_head); int find_last_nth(struct node *linklist_head, int n); void reverse_linklist(struct node *linklist_head);#endif //main.c#include stdio.h #include linklist.hint main(void) {int n;create_list(1);create_list(2);create_list(3);create_list(4);create_list(5);create_list(6);create_list(7);create_list(8);create_list(9);create_list(10);print_linklist(head);reverse_linklist(head);print_linklist(head);return 0; }逆置链表(双向链表) //linklist.c#include linklist.h #include stdlib.hstruct node *head NULL; struct node *tail NULL;void create_list(unsigned int elem) {struct node *p (struct node *)malloc(sizeof(struct node));p-elem elem;p-pre NULL;p-next NULL;if(head NULL)head p;else{tail-next p;p-pre tail;}tail p; }void insert_node(int pos, unsigned int elem) {struct node *pre;pre head;int i 0;struct node *p (struct node *)malloc(sizeof(struct node));if(pos 0){p-elem elem;p-next head;head-pre p;p-pre NULL;head p;}else{while(i pos - 1){pre pre-next;i;}p-elem elem;p-pre pre;p-next pre-next;if(p-next ! NULL)pre-next-pre p; pre-next p;if(p-next NULL)tail p;} }void delete_node(int pos) {struct node *pre, *p;pre head;int i 0;if(pos 0){head head-next;head-pre NULL;free(pre);}else{while(i pos - 1){pre pre-next;i;}p pre-next;pre-next p-next;if(p-next ! NULL)p-next-pre pre;else//if(p-next NULL)tail pre;free(p);} }void print_linklist(void) {struct node *p;for(p head; p; p p-next)printf(%5d, p-elem);printf(\n); }int search(unsigned int elem) {struct node *p;for(p head; p; p p-next)if(p-elem elem)return 1;return 0; }void reverse_print_linklist(void) {struct node *p;for(p tail; p; p p-pre)printf(%5d, p-elem);printf(\n); }//linklist.h#ifndef LINKLIST_H__ #define LINKLIST_H__#include stdio.hstruct node {unsigned int elem;struct node *pre;struct node *next; };void create_list(unsigned int elem); void insert_node(int pos, unsigned int elem); void delete_node(int pos); void print_linklist(void); int search(unsigned int elem); void reverse_print_linklist(void);#endif //main.c#include stdio.h #include linklist.hint main(void) {create_list(1);create_list(2);create_list(3);create_list(4);create_list(5);create_list(6);create_list(7);print_linklist();reverse_print_linklist(); /*insert_node(0, 11);print_linklist();delete_node(6);print_linklist();delete_node(0);print_linklist();delete_node(0);print_linklist();delete_node(4);print_linklist();insert_node(0, 8);print_linklist();insert_node(5, 9);print_linklist();insert_node(2, 13);print_linklist(); */ return 0; }
http://www.hkea.cn/news/14413369/

相关文章:

  • 做挖机配件销售的网站网站建设所需美工
  • 一个网络空间做两个网站营业推广名词解释
  • 做医院的网站 配色怎么选择如何做阿里巴巴的网站
  • 怎样建立俄罗斯网站大兴网站建设费用
  • 网站优化需求平面构成创意与设计
  • 三合一网站建设什么意思南宁平台公司
  • seo网站营销推广全...免费室内设计网站都有哪些
  • 网站建设肆金手指排名4电商网站制作成手机app
  • 上海崇明林业建设有限公司 网站什么做网站站群
  • 坑梓做网站公司怎么样wordpress 多分类
  • 做效果图的外包网站平面设计教程网站有哪些
  • 网站建设栏目这一块怎么写兰州新区农投建设网站
  • 平面设计基础教程seo静态页源码
  • 怎样在网站上做办公家具怎样安装微信小程序
  • 还有哪些网站可以做H5wordpress配置网络
  • 大连市网站制作电话wordpress 标签特效
  • 上海网站建设哪家强做网站推广产品
  • 网站开发参考资料网站被攻击会影响收录么
  • 自己做网站的服务器广州做网站哪家公司好
  • 哪些网站是.net开发的李沧网站建设谁家好
  • 如何网站做外贸生意网站改版的费用
  • 桂林商品房做民宿在哪个网站登记好备案的网站 能拿来做仿站吗
  • 家居网站建设营销推广长乐市住房和城乡建设局网站
  • 成都电子商务网站建设wordpress插件vip
  • seo网站关键词排名软件流量对网站的作用
  • 网站后台统计企业所得税5%的标准
  • 济南新网站建设响水做网站的价格
  • 厦门市城市建设档案馆网站怎么给网站 做排名
  • 安全狗iis版删了以后 网站打不开优秀甜品网站
  • 深圳市专业的做网站广东网站备案电话号码