| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 418 人关注过本帖
标题:链表的初始化,插入,删除,查找。只写了链表的插入,后面的求补充
只看楼主 加入收藏
一样的
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-4-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
链表的初始化,插入,删除,查找。只写了链表的插入,后面的求补充
#include <iostream>

using namespace std;

int NodeNumber = 0;
struct spra
{
     char name;
     spra *next;
};

spra *creat(int &number);//创建链表
void search(spra *head);
void show(spra *head);//遍历
int find(spra *head);

int main()
{
     spra *head;
     int number = 0;
     head = creat (number);
     cout <<"你输入的字符数是:" <<find(head) <<endl;
     show (head);
     search(head);
     show(head);
     return 0;
}

spra *creat(int &number) //创建链表
{
        spra *head = NULL;
     spra *pend = head;
     spra *ps;
     char temp;
     cout <<"请输入字符:"<<endl;
     do
     {
         cin >>temp;
         if (temp != '#')
         {
             ps = new   spra;
             ps->name = temp;
             ps->next = NULL;
             if (head == NULL)
             {
                 head = ps;
             }
             else
             {
                 pend->next = ps;
             }
             pend = ps;
             number++;
         }
     }while (temp != '#');
     return head;
}

void show (spra *head)   //遍历
{
     cout <<"你输入的字符如下:"<<endl;
     spra *te = head;
     while (te != NULL)
     {
         cout <<te->name;
         te = te->next;
     }
     cout <<endl;
}

void search(spra *head)
{
     spra *al = head;
     spra *NewNode = new spra;
     cout <<"->"<<endl;
     NewNode->name = '!';
     while (al != NULL)
     {
         if (al->name == 'a')
         {
             NewNode->next = al->next;
             al->next = NewNode;
             search(NewNode->next);
         }
         al = al->next;
     }
}

int find(spra *head)
{
     spra *s = head;
     while(s != NULL)
     {
         NodeNumber++;
         s = s->next;
     }
     return NodeNumber;
}
搜索更多相关主题的帖子: include search number return 
2014-04-25 15:06
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:20 
搞懂了“插入”的原理,自然知道怎麽刪除和查找,後面的不會,祗能表明你的插入是抄來的。

授人以渔,不授人以鱼。
2014-04-26 12:30
快速回复:链表的初始化,插入,删除,查找。只写了链表的插入,后面的求补充
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018063 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved