📄 c-c++中结构体(struct)知识点强化 [c-c++].htm
字号:
<BR>test *create() <BR>{
<BR> test *ls;<FONT
color=green>//节点指针 </FONT>
<BR> test *le;<FONT
color=green>//链尾指针 </FONT>
<BR> ls <FONT
color=red>=</FONT> <FONT
color=blue>new</FONT> test;<FONT
color=green>//把ls指向动态开辟的堆内存地址 </FONT>
<BR> <FONT
color=maroon>cin</FONT>>>ls->name>>ls->socre;
<BR> head=NULL;<FONT
color=green>//进入的时候先不设置head指针指向任何地址,因为不知道是否一上来就输入null跳出程序 </FONT>
<BR> le=ls;<FONT
color=green>//把链尾指针设置成刚刚动态开辟的堆内存地址,用于等下设置le->next,也就是下一个节点的位置 </FONT>
<BR> <BR> <FONT
color=blue>while</FONT>(strcmp(ls->name,"null")!=0)<FONT
color=green>//创建循环条件为ls->name的值不是null,用于循环添加节点 </FONT>
<BR> {
<BR> <FONT
color=blue>if</FONT>(head==NULL)<FONT
color=green>//判断是否是第一次进入循环 </FONT>
<BR> {
<BR> head=ls;<FONT
color=green>//如果是第一次进入循环,那么把引导进入链表的指针指向第一次动态开辟的堆内存地址 </FONT>
<BR> }
<BR> <FONT
color=blue>else</FONT>
<BR> {
<BR> le->next=ls;<FONT
color=green>//如果不是第一次进入那么就把上一次的链尾指针的le->next指向上一次循环结束前动态创建的堆内存地址 </FONT>
<BR> }
<BR> le=ls;<FONT
color=green>//设置链尾指针为当前循环中的节点指针,用于下一次进入循环的时候把上一次的节点的next指向上一次循环结束前动态创建的堆内存地址 </FONT>
<BR> ls=<FONT
color=blue>new</FONT> test;<FONT
color=green>//为下一个节点在堆内存中动态开辟空间 </FONT>
<BR> <FONT
color=maroon>cin</FONT>>>ls->name>>ls->socre;
<BR> } <BR>
<BR> le->next=NULL;<FONT
color=green>//把链尾指针的next设置为空,因为不管如何循环总是要结束的,设置为空才能够在循环显链表的时候不至于死循环 </FONT>
<BR> <FONT
color=blue>delete</FONT> ls;<FONT
color=green>//当结束的时候最后一个动态开辟的内存是无效的,所以必须清除掉 </FONT>
<BR> <FONT
color=blue>return</FONT> head;<FONT
color=green>//返回链首指针 </FONT> <BR>} <BR>
<BR><FONT
color=blue>void</FONT> showl(test *head)
<BR>{ <BR> <FONT
color=maroon>cout</FONT><<"链首指针:"<<head<<endl;
<BR> <FONT
color=blue>while</FONT>(head)<FONT
color=green>//以内存指向为null为条件循环显示先前输入的内容 </FONT>
<BR> {
<BR> <FONT
color=maroon>cout</FONT><<head->name<<"|"<<head->socre<<endl;
<BR> head=head->next;
<BR> } <BR>} <BR>
<BR><FONT color=blue>void</FONT> <FONT
color=blue>main</FONT>() <BR>{
<BR> showl(create());
<BR> <FONT
color=maroon>cin</FONT>.get();
<BR> <FONT
color=maroon>cin</FONT>.get(); <BR>} </P>
<P> 上面的代码我们是要达到一个目的:就是要存储你输入的人名和他们的得分,并且以链状结构把它们组合成一个链状结构。
</P>
<P>
<TABLE cellSpacing=0 cellPadding=3 width="96%" align=center
border=0>
<TBODY>
<TR>
<TD class=article align=right><FONT
style="COLOR: #ff0000">[1] </FONT><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_1.html"
target=_self>[2] </A><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_2.html"
target=_self>[3] </A><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_3.html"
target=_self>[4] </A><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_4.html"
target=_self>[5] </A><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_5.html"
target=_self>[6] </A><A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942_1.html">[下一页]</A></TD></TR></TBODY></TABLE><BR>
<TABLE style="CLEAR: both" cellSpacing=0 cellPadding=0
width="96%" align=center border=0>
<TBODY>
<TR>
<TD align=middle><A name=_comment_tag_>正在加载评论,请稍候…</A>
<SCRIPT id=_comment_script_ defer></SCRIPT>
<SCRIPT>_comment_script_.src="http://cmt.pconline.com.cn/?";</SCRIPT>
</TD></TR></TBODY></TABLE>
<DIV align=center><BR><SPAN id=xl_550>ad</SPAN>
<TABLE
style="BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid"
cellSpacing=0 width=414 bgColor=#f7f8f9 border=0>
<TBODY>
<TR>
<TD>
<DIV id=demoo
style="OVERFLOW: hidden; WIDTH: 380px; HEIGHT: 20px">
<DIV id=demoo1>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD width=201 height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1124838&forum=5"
target=_blank>6800SLI系统登场</A></TD>
<TD width=183 height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1126046"
target=_blank>疯狂,6600_AGP标准版小测</A></TD></TR>
<TR>
<TD height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1098824"
target=_blank>家文:升技NF8主板测试报告!</A></TD>
<TD height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1124236&forum=4"
target=_blank>6600GT AGP扔入珠江? </A></TD></TR>
<TR>
<TD height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1122532&forum=5"
target=_blank>看图猜哪颗CPU超频极限最强!</A></TD>
<TD height=18>·<A
href="http://itbbs.pconline.com.cn/traditional/article.jsp?topic=1063634"
target=_blank>无法访问网上邻居解决方案集</A></TD></TR></TBODY></TABLE></DIV>
<DIV id=demoo2></DIV></DIV>
<SCRIPT>
var speed=100
demoo2.innerHTML=demoo1.innerHTML
function Marquee(){
if(demoo2.offsetTop-demoo.scrollTop<=0)
demoo.scrollTop-=demoo1.offsetHeight
else{
demoo.scrollTop++
}
}
var MyMar=setInterval(Marquee,speed)
demoo.onmouseover=function() {clearInterval(MyMar)}
demoo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}</SCRIPT>
</TD></TR></TBODY></TABLE></DIV>
<TABLE
style="BORDER-TOP: #303880 1px solid; BORDER-BOTTOM: #303880 1px solid"
height=30 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR align=middle>
<TD width="9%"></TD>
<TD noWrap width="15%"><IMG height=17
src="C-C++中结构体(struct)知识点强化 [C-C++].files/commend.gif"
width=17 align=absMiddle> <A
href="http://www.pconline.com.cn/script/email.html?C/C++中结构体(struct)知识点强化&http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942.html"
target=_blank>发给好友 </A></TD>
<TD noWrap width="18%"><IMG height=17
src="C-C++中结构体(struct)知识点强化 [C-C++].files/commend6.gif"
width=17 align=absMiddle nowrap> <A
href="http://guide.pconline.com.cn/suggest/post.jsp">我要报错</A></TD>
<TD noWrap width="19%"><IMG height=17
src="C-C++中结构体(struct)知识点强化 [C-C++].files/commend1.gif"
width=17 align=absMiddle nowrap> <A
href="http://ittg.pc.com.cn/contribute_pconline/contribute.jsp">投稿给我们</A></TD>
<TD noWrap width="14%"><IMG height=17
src="C-C++中结构体(struct)知识点强化 [C-C++].files/commend4.gif"
width=17 align=absMiddle nowrap> <A
href="javascript:window.external.AddFavorite('http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942.html',%20'C/C++中结构体(struct)知识点强化')">加入收藏</A></TD>
<TD width="14%" height=24><IMG height=17
src="C-C++中结构体(struct)知识点强化 [C-C++].files/commend3.gif"
width=17 align=absMiddle> <A
href="http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/567942.html#">返回顶部</A></TD>
<TD width="11%"
height=24></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE
style="BORDER-TOP: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"
cellSpacing=0 cellPadding=0 width="100%"
background=C-C++中结构体(struct)知识点强化 [C-C++].files/xgart_bg.gif
border=0>
<TBODY>
<TR>
<TD width=40><IMG height=23
src="C-C++中结构体(struct)知识点强化 [C-C++].files/xgart_biao.gif"
width=40></TD>
<TD width=251>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD
class=font4><STRONG>本栏今日更新</STRONG></TD></TR></TBODY></TABLE></TD>
<TD style="BORDER-LEFT: #000000 1px solid" width=40><IMG
height=23
src="C-C++中结构体(struct)知识点强化 [C-C++].files/xgart_biao.gif"
width=40></TD>
<TD width=250>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD
class=font4><STRONG>相关文章</STRONG></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=middle width=291 bgColor=#f7f8f9>
<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0>
<TBODY>
<TR>
<TD class=sfont>·<A
href="http://www.pconline.com.cn/pcedu/softnews/dongtai/0503/567868.html">绝对震撼!微软将WinFS向WinXP移植</A><BR>·<A
href="http://www.pconline.com.cn/pcedu/softnews/dongtai/0503/567867.html">Longhorn通讯系统Indigo本月亮相</A><BR>·<A
href="http://www.pconline.com.cn/pcedu/pingce/0503/567864.html">Netscape
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -