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

dede网站仿站经典工具软件ui设计教程

dede网站仿站经典工具,软件ui设计教程,四川省建设厅官方网站,百度短链接n个节点的二叉树n1Given a linked list and an integer n, append the last n elements of the LL to front. Assume given n will be smaller than length of LL. 给定一个链表和一个整数n#xff0c;将LL的最后n个元素附加到前面。 假设给定的n将小于LL的长度。 Input form…n个节点的二叉树n1Given a linked list and an integer n, append the last n elements of the LL to front. Assume given n will be smaller than length of LL. 给定一个链表和一个整数n将LL的最后n个元素附加到前面。 假设给定的n将小于LL的长度。 Input format: Line 1: Linked list elements (separated by space and terminated by -1 输入格式第1行链接的列表元素(以空格分隔并以-1终止 Sample Input 1 : 1 2 3 4 5 -1 3 Sample Output 1 : 3 4 5 1 2 Description: 描述 The question asks us to append the last N nodes to front, i.e the new linked list should first start from those N nodes and then traverse the rest of the nodes through the head of the old linked list. 这个问题要求我们将最后的N个节点附加到前面即新的链表应首先从这N个节点开始然后再通过旧链表的头遍历其余节点。 Example: 例 For Linked List 1-2-3-4-5-6-NULL To append the last 2 nodes, the new linked list should be: 5-6-1-2-3-4-NULL Solution Explanation: 解决方案说明 To solve this problem, we take two pointers temp and t and point both of them to the head of the linked list. We take another variable i and equate it to – n. This i is used for finding out the head of the new linked list. Then we traverse the loop while temp ! NULL. In the loop we check that if(i0) i.e temp is now n nodes away from t, t t- next. We will update i and temp temp-next on each traversal. At last, we update temp- next head, head t - next and t- next NULL. 为了解决这个问题我们使用两个指针temp和t并将它们都指向链接列表的开头。 我们采用另一个变量i并将其等于– n 。 我用于查找新链表的标题。 然后我们在temp NULL时遍历循环。 在循环中我们检查if(i 0)即temp现在距离t距离n个节点 t t- next 。 我们将在每次遍历时更新i 和temp temp- next 。 最后我们更新temp- next head head t- next和t- next NULL 。 Algorithm: 算法 STEP 1: Declare the function appendNNode with parameters (Node* head, int n) 步骤1使用参数声明函数appendNNode (Node * headint n) STEP 2: Declare two variables Node * temp , t and point both of them to head. 步骤2声明两个变量Node * temp t并将它们都指向head。 STEP 3: Declare int i -n 步骤3声明int i -n STEP 4: Repeat Step 5 and 6, while(temp-next ! NULL) 步骤4重复步骤5和6 同时(temp- next NULL) STEP 5: if(i0) t t- next. 步骤5 if(i 0)t t- next 。 STEP 6: temp temp- next, i. 步骤6 temp temp-接下来i 。 STEP 7: temp-next head, head t-next, and t- next NULL 步骤7 temp- next head head t- next和t- next NULL STEP 8: return head 步骤8返回头 Steps: 脚步 At first: 1-2-3-4-5-6-NULL, t-1 and temp-1. After complete traversal: 1-2-3-4-5-6-NULL, t-4 and temp-6. So, temp-next head and head t-next i.e 5-6-1-2-3-4 --- (reconnecting to 5) Atlast, t- next NULL i.e 5-6-1-2-3-4-NULL .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } Function: 功能 Node *appendNNodes(Node* head, int n){ // Two pointers, one for traversal and // other for finding the new head of LL Node *temp head, *t head; //index maintained for finding new head int i -n; while(temp-next!NULL){ //When temp went forward n nodes from t if(i0){ t t-next; } temp temp -next; i; } //Connecting the tail to head temp-next head; //Assigning the new node head t-next; //Deleting the previous connection t-next NULL; return head; } C Code: C 代码 #includebits/stdc.h using namespace std; struct Node{// linked list Node int data; Node * next; }; Node *newNode(int k){ //defining new node Node *temp (Node*)malloc(sizeof(Node)); temp-data k; temp-next NULL; return temp; } //Used to add new node at the end of the list Node *addNode(Node* head, int k){ if(head NULL){ head newNode(k); } else{ Node * temp head; Node * node newNode(k); while(temp-next! NULL){ temp temp-next; } temp- next node; } return head; } // Used to create new linked list and return head Node *createNewLL(){ int cont 1; int data; Node* head NULL; while(cont){ coutEnter the data of the Nodeendl; cindata; head addNode(head,data); coutDo you want to continue?(0/1)endl; cincont; } return head; } //To print the Linked List void *printLL(Node * head){ while(head! NULL){ couthead-data-; head head- next; } coutNULLendl; } //Function Node *appendNNodes(Node* head, int n){ // Two pointers, one for traversal and // other for finding the new head of LL Node *temp head, *t head; //index maintained for finding new head int i -n; while(temp-next!NULL){ //When temp went forward n nodes from t if(i0){ t t-next; } temp temp -next; i; } //Connecting the tail to head temp-next head; //Assigning the new node head t-next; //Deleting the previous connection t-next NULL; return head; } //Driver Main int main(){ Node * head createNewLL(); coutThe linked list isendl; printLL(head); int data; coutEnter the number of nodes you want to append.endl; cindata; head appendNNodes(head,data); coutThe new Linked List is endl; printLL(head); return 0; } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } Output 输出量 Enter the data of the Node 1 Do you want to continue?(0/1) 1 Enter the data of the Node 2 Do you want to continue?(0/1) 1 Enter the data of the Node 3 Do you want to continue?(0/1) 1 Enter the data of the Node 4 Do you want to continue?(0/1) 1 Enter the data of the Node 5 Do you want to continue?(0/1) 1 Enter the data of the Node 6 Do you want to continue?(0/1) 1 Enter the data of the Node 7 Do you want to continue?(0/1) 0 The linked list is 1-2-3-4-5-6-7-NULL Enter the number of nodes you want to append. 3 The new Linked List is 5-6-7-1-2-3-4-NULL 翻译自: https://www.includehelp.com/cpp-programs/append-last-n-nodes-to-first-in-the-linked-list.aspxn个节点的二叉树n1
http://www.zqtcl.cn/news/300842/

相关文章:

  • 用备案的网站做违法网站wordpress个性404
  • 中国制造网官方网站下载安装我国做民宿的网站
  • 英文网站seo广州市软件开发有限公司
  • 锦州网站建设渠道山西做网站的公司有哪些
  • 4线城市搞网站开发丹灶网站建设公司
  • 青岛网站建设seo优化wordpress分类标题自定义
  • 网站开发本地环境在海南注册公司需要多少钱
  • 济南网站开发去哪儿旅行app下载安装
  • 大城 网站北京做网站男生工资
  • 赣州网站建设百家号免费软件网
  • 在合肥做网站多少钱网站开发外包平台
  • 百度指数查询平台网站建设SEO优化哪家好
  • 网站怎么在成都备案中企动力如何
  • 免费数据统计网站app推广拉新一手渠道
  • 网站推广效果不好原因zac seo博客
  • 高端网站设计合肥网站建设个人网站建设公
  • 廊坊建站模板系统做效果图的网站
  • 建网站打开需要验证四川省成都市建设厅官网
  • 网站文章列表如何排版珠海建设工程信息网站
  • 郑州个人做网站建设银行招聘网站
  • 杭州网站设计公司联系亿企邦网站怎么上百度
  • 网站建设的未来网站不备案访问
  • 网站改版效果图怎么做网站建设的五个基本要素
  • 河南建站网站做o2o网站需要多少钱
  • 重庆企业网站定制开发公司wordpress用户页
  • 电子商务网站seo网站规划与设计方向
  • 外贸双语网站源码wordpress 柚子
  • 隆昌市住房和城乡建设厅网站html5网页成品代码
  • 泉州丰泽建设局网站wordpress设置logo和公司名
  • 网页与网站设计实验总结网上商城互联网网站开发