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

常州营销网站建设开化网站建设公司

常州营销网站建设,开化网站建设公司,互联网产品营销策划方案,网络工具c语言i和i程序Given a sorted linked list (elements are sorted in ascending order). Eliminate duplicates from the given LL, such that output LL contains only unique elements. 给定一个排序的链表(元素按升序排序)。 从给定的LL中消除重复项#xff0c;以便输出LL仅…c语言i和i程序Given a sorted linked list (elements are sorted in ascending order). Eliminate duplicates from the given LL, such that output LL contains only unique elements. 给定一个排序的链表(元素按升序排序)。 从给定的LL中消除重复项以便输出LL仅包含唯一元素。 Input format: Linked list elements (separated by space and terminated by 1) 输入格式链接列表元素(以空格分隔并以1终止) Sample Input 1 : 1 2 3 3 3 4 4 5 5 5 7 -1 Sample Output 1 : 1 2 3 4 5 7 Description: 描述 In this question, we are given a sorted linked list with duplicate elements in it. Our task is to remove the duplicate nodes of the linked list. Since the list is sorted, the duplicate elements will be present in consecutive orders, that makes the work a lot easier. 在这个问题中我们得到一个包含重复元素的排序链表。 我们的任务是删除链表的重复节点。 由于列表已排序因此重复的元素将以连续的顺序显示这使工作变得更加容易。 Example: 例 Lets the list be: 1-2-3-3-4-4-4-NULL The modified list will be: 1-2-3-4-NULL Solution Explanation: 解决方案说明 To solve this problem, we keep the temp pointer pointing to node. While(temp - next ! NULL), we check if the data of temp is equal to data of temp-next. If they are equal, we will point the temp- next to temp - next -next. Original LL: 3- 3- 4- ... After Change: 3- 4- ... Leaving out the middle 3- 为了解决这个问题我们使临时指针指向节点。 while(temp- next NULL)时我们检查temp的数据是否等于temp- next的数据。 如果它们相等则将temp-指向temp- next- next。 原始LL3- 3- 4- ... 更改后3- 4- ...省略中间3- This will keep on until we reached the end of the list and return head at the end. 这将一直持续到我们到达列表的末尾并返回末尾。 Steps 脚步 1. 1-2-3-3-4-4-4-NULL, temp 1 2. 1-2-3-3-4-4-4-NULL, temp 2 3. 1-2-3-3-4-4-4-NULL, temp 3 4. 1-2-3-4-4-4-NULL, temp 4 5. 1-2-3-4-4-NULL, temp 4 Finally, 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 *removeDuplicate(Node* head){ //temp pointing to head Node *temp head; while(temp-next ! NULL temp ! NULL){ //Duplicate Found if(temp-data temp-next-data){ //DUplicate Removed temp - next temp -next -next; } else{ //No Duplicate Present temp temp-next; } } //Return Head 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 *removeDuplicate(Node* head){ //temp pointing to head Node *temp head; while(temp-next ! NULL temp ! NULL){ //Duplicate Found if(temp-data temp-next-data){ //DUplicate Removed temp - next temp -next -next; } else{ //No Duplicate Present temp temp-next; } } //Return Head return head; } //Driver Main int main(){ Node * head createNewLL(); coutThe linked list isendl; printLL(head); head removeDuplicate(head); 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 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 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 5 Do you want to continue?(0/1) 1 Enter the data of the Node 5 Do you want to continue?(0/1) 0 The linked list is 1-1-2-2-3-4-5-5-5-NULL The new Linked List is 1-2-3-4-5-NULL 翻译自: https://www.includehelp.com/cpp-programs/eliminate-duplicates-from-linked-list.aspxc语言i和i程序
http://www.pierceye.com/news/145670/

相关文章:

  • 全美网站开发微转app是用网站做的吗
  • 禹州 什么团购网站做的好广州网站建设程序开发
  • 成都市微信网站建设公司专业app开发
  • 郑州网站建设hndream神木网站设计公司
  • 关于网站集约化建设的讲话抓取网站访客qq号码
  • 南昌住房城市建设支行官方网站海洋网络提供网站建设
  • 网站外链建设的八大基本准则做网站卖得出去吗
  • 网站建设不完整 审核天元建设集团有限公司一公司尤作岭
  • 论坛程序做导航网站专做轮胎的网站
  • 网站开发软件解决方案个人网站可以做资讯吗
  • 网站右击无效是怎么做的牛商网建设的食品网站
  • 新北网站建设全网营销网站建设
  • 网站建设与管理 教学设计自己的身份已经网站备案了
  • 长沙网站列表网站开发实例及研究
  • 东莞阳光网官方网站吉林百度查关键词排名
  • 网站开发投标书范本目录左旗网站建设
  • 一流的五屏网站建设wordpress 移动端 接口
  • 服装行业网站建设兴宁网站设计
  • 网站两边的悬浮框怎么做wordpress 非插件代码高亮
  • 网站安全管理制度建设下载网站建设公司哪家强
  • 网络直播网站开发长春市城乡建设部网站
  • 自己搭建服务器做网站要多久汕头网络推广电话
  • 除了昵图网还有什么做图网站深圳房地产网站开发
  • 网站建设哪家go好重庆怎样网站推广
  • 松江网站建设哪家好wordpress去掉父分类
  • 网站 云建站设计网站推荐室内
  • 网站怎么自适应屏幕云南建设投资集团网站
  • qq中心官方网站两个网站如何使用一个虚拟主机
  • 泰安网站制作推荐电脑网页游戏排行榜前十名
  • 石家庄最好的网站建设公司上海都有哪些企业公司