永发信息网

使用c++中的单链表完成问题(1)从键盘输入10个整数,产生顺序表,并输入结点值

答案:2  悬赏:50  手机版
解决时间 2021-03-09 18:37
(1)从键盘输入10个整数,产生顺序表,并输入结点值
(2)从键3盘输入1个整数,在顺序表中查找该结点的位置,若找到,输出结点的位置,若找不到,则显示"找不到"
→用单链表实现←
最佳答案
首先顺序表不是链表哦,顺序表是内存连续的一种线性表,比如数组。第一个到底是产生顺序表还是链表呢?
全部回答

    //实现链表倒置,如链表存储的是1,2,3,倒置后为3,2,1 #include <iostream> using namespace std; //定义链表 typedef struct node { int data; node * next; }node; //创建链表 node* createlist(int &n) { node *tmp, *head = null, *tail = null; int num; cin>>num; head = new node; if(head == null) {   cout<<"no memory available!";   return null; } head->data = num; head->next = null; tail = head; for(int i=0; i<n-1; i++) {   cin>>num;   tmp = new node;   if(tmp == null)   {    cout<<"no memory available!";    return null;   }   tmp->data = num;   tmp->next = null;   tail->next = tmp;   tail = tmp; } return head; } //链表倒置 node* inversionlist(node *head) { if(head == null || head->next == null) {   return head; } node *connode = head->next; node *curnode = connode->next; head->next = null; while(curnode != null) {   connode->next = head;   head = connode;   connode = curnode;   curnode = curnode->next; } connode->next = head; head = connode; return head; }

//打印     void printlist(node *head) { node *curnode = head; while(curnode != null) {   cout<<curnode->data<<"\t";   curnode = curnode->next; } } //删除链表,释放内存 void deleteallnode(node *head) { node *p = null; while(head != null) {   p = head;   head = head->next;   delete p;   p = null; } } void main() { int n; cout<<"please input the number of node:"; cin>>n; node *head = createlist(n); node *newhead = inversionlist(head); printlist(newhead); deleteallnode(newhead);

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
花园办事处邝花园村一体化管理卫生室NO.4这个
iphone7plus港版和国行有什么区别?
桂林到灵川的车费多少?
人们常见的“蜻蜓点水”,实际上是蜻蜓在CA.
ssd启动黑屏很久
PScs2怎么切圆
为了获得较好的观赏效果,在旅游前必须做的工
万象网管系统退出后如何再次启动?
祖坟阴宅风水对后人的影响大吗
cf玫瑰精灵跟黑龙 雷神哪个好 说理由!!
最近要去法院调解是房产买卖纠纷请问需要做哪
数学应用题/行政能力测验题某校下午2点整派车
啥配置的电脑算高配置?
石化旗舰店地址在什么地方,想过去办事
从福州出发到漳州火山岛公园的旅行规划,求大
推荐资讯
1.比例尺表示 比 缩小的程度,比例尺的公式是
进口设备计算应纳增值税时,计税价格应由下列
“借口”用英语怎么说
念禧缘馄饨·水饺地址在哪,我要去那里办事
面料印花是什么意思
原拱桥巷羊瘪在什么地方啊,我要过去处理事情
linux多个扩展分区
现加入优步特供雷凌1.5t,但易车网查了没有1.
圆通快递在北京中转,一直显示已打包,但没显
桂附地黄丸大蜜丸怎么吃嚼着吃难吃死了,怎么
工商的坐标值密码M5:L4对应的密码是什么
两个月大杜高犬经常发出呼哧呼哧声然后咳一下
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?