网龙笔试题:1、实现链表的创建,删除和逆序等
#include#includeusingnamespacestd;typedefstructstu{intdata;structstu*next;}node,list;node*creatlist(intn){node*h,*p,*s;h=newnode;h->next=NULL;p=h;coutnext;}if(s==NULL){coutnext;deletes;}}voiddisplay(node*h){h=h->next;while(h
=NULL){coutnext;q->next=p;p=q;q=s;}q->next=p;h->next->next=NULL;h->next=q;returnh;}intmain(){intn;node*h;coutn;h=creatlist(n);display(h);coutn;deletelist(h,n);display(h);h=reverse(h);display(h);return0;}2、字符串逆序输入文件是in
txt,内容例如如下:hello,everyone
mynameisshen,he
则倒序之后为:everyone
hello,he
shen,isnamemyne
ni,源程序,自己实现的,算法是别人的
呵呵#include#include#include#include#includeusingnamespacestd;intmain(){ifstreaminFile;ofstreamoutFile;char*fName;string::size_typeb,e;charch;stringline;vectorsvec;inFile
open(”in
txt”);while(getline(inFile,line))//先获取每一行字符,并存入