c语言建立链表表

相关文章推荐:
数据结构实验之链表二:逆序建立链表
输入整数个数N,再输入N个整数,按照这些整数输入的相反顺序建立单链表,并依次遍历输出单链表的数据。
第一行输入整数N;;
第二行依次输入N个整数,逆序建立单链表。
依次输出单链表所存放的数据。
11 3 5 27 9 12 43 16 84 22
22 84 16 43 12 9 27 5 3 11
贴一下代码吧:
#include &stdio.h&
#include &malloc.h&
typedef struct Node
阅读(90) 回复(0)
其他文章推荐
一、结点结构
单链表的数据结构定义如下:
typedef struct node
struct node *
其中,ElemType可以是任意数据类型如int、float或者char等,在算法中,规定其默认为int类型。
二、带头结点
本文描述的是单链表逆序,链表逆序需要维护3个指针,分别指向...
架构设计与优化
阅读(0) 回复(0)
一、结点结构
双向链表的数据结构定义如下:
typedef struct node
struct node *prior
struct node *
其中,ElemType可以是任意数据类型如int、float或者char等,在算法中,规定其默认为int类型。
二、带头结点
本文描述的是双向链...
架构设计与优化
阅读(0) 回复(0)
#include &stdlib.h&
#include &stdio.h&
#include &string.h&
//bool IsPrimerNum(int Num)
// if (Num &= 1)
// for (int i=2;i &= Num/2;i++)
if (0 == Num % i)
void stringReverse(char* srcStr,int star,int end)
while(star & end)
char chrTemp = srcStr[star];
srcStr[star]
阅读(0) 回复(0)
双向循环链表
双向不循环链表(主要用于散列表表)
阅读(30) 回复(0)
http://zh.wikipedia.org/wiki/%E5%BE%AA%E7%8E%AF%E9%93%BE%E8%A1%A8
/link?url=4oKLiMW04sCwe621i4xPRUD7WlIo1pFr7E0MRLTtbLUwfMAmn5SRDmrr_gEqFUCyB4n-IoM77XZ5IeCL3FdTIcv_wUsM6oDZ6eljBidMzSC
阅读(30) 回复(0)
一道笔试题,将字符串逆序。#include &stdio.h&
#include &assert.h&
#include &malloc.h&
#include &string.h&
** 函数名:str_reverse
** 输入参数:char *str:原字符串
** 返回值:char *ret_char:逆序后的字符串
** 功能:将字符串逆序,如将&abcdef&转换成&fedcba&
char *str_reverse(char* str)
int i=strlen(str);
char *temp = (char *)malloc(sizeof(str)); //在堆区(heap)为temp分配内存,存储逆序后的字...
阅读(0) 回复(0)
#include &stdio.h&#include &stdlib.h&#include &string.h&
struct single_link{ struct single_link * struct single_link * };
int main(void){ struct single_link *head=NULL,*tail=NULL,*tmp=NULL,*i_d_tmp=NULL; int i=0,j=0; for(i=0;i&5;i++) {
tmp=(struct single_link *)malloc(sizeof(struct single_link));
tmp-&data=i+1;
tmp-&next =NULL;
tmp-&prev=NULL;
if(head...
阅读(0) 回复(0)
#include &stdio.h&#include &stdlib.h&#include &string.h&
struct single_link{ struct single_link * struct single_link * };
int main(void){ struct single_link *head=NULL,*tail=NULL,*tmp=NULL,*i_d_tmp=NULL; int i=0,j=0; for(i=0;i&5;i++) {
tmp=(struct single_link *)malloc(sizeof(struct single_link));
tmp-&data=i+1;
tmp-&next =NULL;
tmp-&prev=NULL;
if(head...
阅读(0) 回复(0)
[原]哈希链表及其变种
阅读238 评论0
先来直观的比较下普通链表和哈希链表:
普通链表的表头和节点相同
struct list_head {
struct list_head *next, *
哈希链表头
struct hlist_head {
struct hlist_node *
阅读(30) 回复(0)
相比较线性表的排序而言,链表排序的内容稍微麻烦一点。一方面,你要考虑数据插入的步骤;另外一方面你也要对指针有所顾虑。要是有一步的内容错了,那么操作系统会马上给你弹出一个exception。就链表的特殊性而言,适合于链表的排序有哪些呢?
(1)插入排序
(2)冒泡排序
(3)希尔排序
(4)选择排序
(5)快速排序
(不适合)
阅读(0) 回复(0)
盛拓传媒:
北京皓辰网域网络信息技术有限公司. 版权所有
北京市公安局海淀分局网监中心备案编号:
广播电视节目制作经营许可证:编号(京)字第1149号
ITPUB推荐文章解答你所有技术难题建立链表_百度知道
实验题目:1. 建立一个链表;2. 输出链表结点个数;3. 删除第M个结点;4. 在第N个结点后插入一个新结点;
#include &stdio.h&#include &stdlib.h&#include &iostream&typedef int ElemTtypedef struct LNode {ElemTstruct LNode *}linklist,*void IinitList(link &L){if(L)delete L;L= (link)malloc(sizeof(LNode)) ;if (!L) exit(1);L-&next=NULL;cout&&&链表已经建立\n&;}int listdelete(link &L,int i,ElemType &e){link p,q;p=L;j=0;while(p-&next&&j&i-1){p=p-&++j;}q=p-&p-&next=q-&e=q-&free(q);cout&&&链表已经删除\n&;return 1;}int listinsert(link &L,int i,ElemType e){link p,q;p=L;j=0;while(p&&j&i-1){p=p-&++j;}q= (link)malloc(sizeof(LNode));q-&date=e;q-&next=p-&p-&next=q; cout&&&链表已经插入\n&;return 1;}void show(link l){p=l;j=0;cout&&&链表的值为:\n&;while(p-&next){cout&&p-&next-&date&&p=p-&}}void destorylinst(link &L){while(L){ link p=L;L=L-&free(p) ;}L=NULL;}void print(){cout&&&------------------------\n&;cout&&&------------------------\n&;}void lookfor(link l,int e){
if(l==NULL)
cout&&&链表未建立,请先构造链表\n& ; else{ int i=0,j=0;p=l-&cout&&&你查找值的位置是:\n & ;while(p){ if(p-&date==e){ j++;cout&&i+1&&}p=p-& i++;}cout&&&查找完毕\n&;if(j==0)cout&&&你查找的值不在链表中 、\n&;} }void main(){ link L=NULL;while(1){cout&&&按0退出\n&&&&按1建立\n&&&&按2插入\n&&&&按3删除\n&&&&按4清空链表\n&&&&按5查找\n& ;print();int a,i,j;cin&&a;switch(a){ case 0: if(L!=NULL)destorylinst(L) ;exit(1);case 1:IinitList(L);k=0;print();show(L) ;cout&&&空的链表\n&;cout&&&链表长度为: &&&k&&print();cout&&&是否要给链表插入值:y----n\n&;yy=getchar();if(yy=='y'){cout&&&请输入值!按回车键后输入下一个,结束输入0再按回车\n&;cin&&while(bb!=0){ k++;listinsert(L,k,bb) ;cin&&}print();show(L) ; cout&&&链表长度为: &&&k&&}print();case 2:if(L!=NULL){cout&&&输入位置:\n&;cin&&i;while(i&k+1 || i&1){cout&&&位置错误,重新输入插入位置\n& ;cin&&i;}cout&&&输入植;\n&;cin&&j;listinsert(L,i,j) ;k++;print();show(L);cout&&&链表长度为:&&&k&&print();}else{ cout&&&链表不存在,请先建链表\n&;print(); }case 3:if(L!=NULL){cout&&&输入位置:\n&;cin&&i;while(i&k || i&1){cout&&&位置错误,重新输入删除位置\n& ;cin&&i;}listdelete (L,i,j);cout&&&你删除的是:\n&;cout&&j&&k--; print();show(L);cout&&&链表长度为:&&&k&&print();}else {cout&&&链表不存在,请先建链表\n&;print();}case 4:destorylinst(L) ;cout&&&链表已经清空\n&;print();case 5:print();cout&&&输入要查找的值;\n&;cin&&z;lookfor(L,z);print();default:}}delete L;}
其他类似问题
链表的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
头插法和尾插法建立单链表
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口C语言建立链表和使用链表_百度知道
C语言建立链表和使用链表
我定义了一个结构体typedef struct {
char num[13];
char name[10];
}SStudent stu[100];现在要用链表来储存结构体(不知可不可以这样说)怎么定义链表和使用链表?可不可以这样定义?struct node{
struct student band_
struct node *};这样的话后面要使用数据还可以从结构体操作吗?
输入函数坏可以用吗?int shuru(Student stud[],int n)/*输入学生信息*/{int i=0,j=0;char sign,x[10];double a=0.0; while(sign!='n'&&sign!='N') { printf(&输入学生学号:&);scanf(&%s&,stu[n+i].num);printf(&输入学生姓名:&); scanf(&%s&,stu[n+i].name); printf(&输入学生的语文、数学、英语:&);scanf(&%d、%d、%d&,&stu[n+i].chinese,&stu[n+i].math,&stu[n+i].english);a=1.0*(stu[n+i].chinese+stu[n+i].math+stu[n+i].english)/3; stu[n+i].aver=a;gets(x); /*清除多余的输入*/ printf(&是否继续输入?(Y/N):\n&);scanf(&%c&,&sign);i++; } return(n+i);}
提问者采纳
可以使用方式如下struct node lsNlsNode.band_inf.math = 100;lsNode.next = NULL;
这样的话是不是我可以这样建立输入函数(在补充里)
可以,不过你最好用malloc分配链表节点空间,用数组会有很多不方便scanf参数要传地址
提问者评价
其他类似问题
按默认排序
其他2条回答
struct node{
Student band_
struct node *};可以。如node1.bank_inf.math
转自 下面的程序是单链表的建立与输出,都有详细的注释,相信你能看的懂但要想学习链表必须得掌握了一定的C语言基础下面这个链表的作用是建立5个结点的单链表,5个结点的值输入以后,依次输出各个结点的值#include&stdio.h&#include&stdlib.h&//链表的建立与输出struct node//定义结点的类型{int num,node*};void main(){node*creat(int n);//函数原型声明void print(node*h);//函数原型声明node*head=0;//定义链头指针并初始化head=creat(5);//调用creat函数创建链表print(head);//调用print函数输出链表}node*creat(int n){node*h=0,*p,*q;for(i=1;i&=n;i++){q=(node*)malloc(sizeof(node));//分配一个结点空间scanf(&%d%d&,&q-&num,&q-&score);//输入新结点的值q-&link=0;//新结点的指针域置0if(h==0)h=q;//第一个结点作为链头结点elsep-&link=q;//新结点添加到链表的末尾p=q;}//返回链头指针}void print(node*h)//链表输出函数的定义{while(h)//当指针h非空时输出h所指结点的值{printf(&num=%d\tscore=%d\n&,h-&num,h-&score);h=h-&//使h指向下一个结点}}
链表的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 链表 的文章

 

随机推荐