首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
判断单链表中是否存在环(网上说的笔试题)
判断单链表中是否存在环(网上说的笔试题)
admin
2019-03-29
101
问题
判断单链表中是否存在环(网上说的笔试题)
选项
答案
#include "stdafx.h" typedef char eleType; // 定义链表中的数据类型 typedef struct listnode // 定义单链表结构 { eleType data; struct listnode *next; }node; node *create(int n) // 创建单链表,n为节点个数 { node *p = (node *)malloc(sizeof(node)); node *head = p; head->data = ’A’; for(int i=’B’; i<’A’+n; i++) { p = (p->next = (node *)malloc(sizeof(node))); p->data = i; p->next = NULL; } return head; } void addCircle(node *head, int n) // 增加环,将链尾指向链中第n个节点 { node *q, *p = head; for(int i=1; p->next; i++) { if(i==n) q = p; p = p->next; } p->next = q; } int isCircle(node *head) // 这是笔试时需要写的最主要函数,其他函数可以不写 { node *p=head,*q=head; while( p->next && q->next) { p = p->next; if (NULL == (q=q->next->next)) return 0; if (p == q) return 1; } return 0; } int main(int argc, char* argv[]) { node *head = create(12); addCircle(head, 8); // 注释掉此行,连表就没有环了 printf("%d\n", isCircle(head)); return getchar(); }
解析
转载请注明原文地址:https://www.kaotiyun.com/show/sRmZ777K
0
程序员面试
相关试题推荐
TheUnitedStatesInterstateHighwaySystemisaninfrastructurefeatofunprecedentedproportions.Notonlydoesitjoinallfi
AnE-mailtoaRoommate写给室友的邮件YouaregoingtostudyabroadandshareanapartmentwithJohn,alocalstudent.Writehimane-
Publicationbiasinacademicjournalsisnothingnew.Afindingofnocorrelationbetweensportingeventsandeitherviolentcri
KimiyukiSudashouldbeaperfectcustomerforJapan’scar-makers.He’sayoung,successfulexecutiveatanInternet-servicesco
ASP.NET与ASP相比,主要有哪些进步?
从当前界面开始,到“电话和调制解调器的选项”中,将系统中的标准56000bps调制解调器删除。
在Excel中,函数ABS(ROUND(-1.478,2))的计算结果是()。A.-1.478B.1.48C.-1.48D.1.5
当线性表采用顺序存储结构实现存储时,其主要特点是
有人说,P2P应用消耗大量的网络带宽,甚至占网络流量的90%。对此的合理解释是______。
在实际应用中,用户通常依靠评价程序来测试系统的性能。以下评价程序中,(16)的评测准确程度最低。事务处理性能委员会(TransactionProcessingPerformanceCouncil,TPC)是制定商务应用基准程序(Benchmark)标
随机试题
试述以人为本的核心要义。
A.挤压心脏的速率为68~80次/分B.每挤压心脏5次后行人工呼吸1次C.每挤压心脏15次后行人工呼吸3次D.每挤压心脏10次后行人工呼吸2次E.每挤压心脏15次后行人工呼吸2次
关于自首,下列说法错误的是?
同一圆管内分别通过流量相同的空气和水,已知空气的运动黏性系数是水的15.7倍,密度是水的1/800,流动处层流区,相同管长条件下()。
(用户名:33;账套:204;操作日期:2011年1月31日)查询库存商品余额表。
会计科目就是账户的名称,它是设置账户的依据,两者核算相同的经济内容,故实质上它们是同一个概念。()
市工商局认定甲公司的行为符合《广告法》第28条第2款第2项规定的“商品或者服务有关的允诺等信息与实际情况不符,对购买行为有实质性影响”情形,属于发布虚假广告。2016年2月10日,向甲公司送达《行政处罚事项告知书》,依法告知甲公司所享有的权利,5日后,又向
Thehealth-careeconomyisrepletewithunusualandevenuniqueeconomicrelationships.Oneoftheleastunderstoodinvolvesthe
Highproductivitydependsonacombinationoffactors,ofwhichthemostimportantareasfollows.individualproductivityThep
INSIPIDNESS:
最新回复
(
0
)