链表基本操作

单链表结构:

typedef struct node

{

  int data;

  struct node *next;

}node;

typedef struct node *LinkList;

/*创建单链表,将新的节点插入到链表的尾部*/

createList(LinkList L, int n)

{

  LinkList p,r;  //p节点用来接收插入的元素,r是尾节点

  int i;

  srand(time(0));

  L=(LinkList)malloc(sizeof(node));

  r=L->next;  //r指向L的尾部

  for(i=0;i<ni++)

  {

    p=(LinkList)malloc(sizeof(node));

    p->data=rand()%100+1;

    r->next=p;  //r指向P

    r=p;  //将r指向新的尾节点

  }

  r->next=NULL;

  return 0;

}

//get the element in the location i
GetElem(LinkList L, int i, int *e)
{
LinkList p; //定义一个指向节点的指针
p=L->next; //p指向链表的第一个节点
int j=1;
while(p&&j<i)
{
p=p->next; //如果P不为空(没有到链表尾部)或者计数器仍然没有到i则p就往前一步
j++;
}
if(j<i||!p)
return 0;
*e=p->data;
return 0;
}

//链表插入,将e插入链表的第i个位置
void ElemInsert(LinkList L, int i, int e)
{
LinkList p,s;
int j=1;
//首先找到
p=L->next;
while(p&&j<i)
{
p=p->next;
j++;
}
//生成一个新节点
s=(LinkList)malloc(sizeof(Node));
s->data=e;
s->next=p->next;
p->next=s;
}

//链表删除,删除第i+1个节点
void ElemDelete(LinkList L, int i, int e)
{
LinkList p,q;
int j=1;
p=L->next;
while(p&&j<i)
{
p=p->next;
j++
}
//考虑一些可能出错的情况
q=p->next;
p->next=q->next;
e=q->data;
free(q); /很重要
}

 

转载于:https://www.cnblogs.com/HIT-wyy-BJTU/archive/2013/05/16/LinkList.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274246.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 投资组合_重新设计投资组合的好处

python 投资组合Yep, I’m here to nag you a bit about that portfolio that you haven’t updated in a while.是的&#xff0c;我在这里想和您谈谈您有一段时间没有更新的作品集。 Yes, it’s time to get to work on it again.是的 &#xff0c;是时候重新开始研究了。 Y…

李安的电影梦by李安

1978年,当我准备报考美国伊利诺大学的戏剧电影系时&#xff0c;父亲十分反感&#xff0c;他给我举了一个数字&#xff1a;在美国百老汇&#xff0c;每年只有200个角&#xff0c;但却有50000人要一起争夺这少得可怜的角色。当时我一意孤行&#xff0c;决意登上了去美国的班机&am…

抓取html中用到的css_如何使用HTML和CSS制作像《星球大战》一样的抓取文字

抓取html中用到的cssThe opening to Star Wars is iconic. The effect of text scrolling both up and away from the screen was both a crazy cool special effect for a movie back in 1977 and a cool typographical style that was brand new at the time.《星球大战》的开…

不安装游戏apk直接启动法

原文地址&#xff1a;http://blog.zhourunsheng.com/2011/09/%E6%8E%A2%E7%A7%98%E8%85%BE%E8%AE%AFandroid%E6%89%8B%E6%9C%BA%E6%B8%B8%E6%88%8F%E5%B9%B3%E5%8F%B0%E4%B9%8B%E4%B8%8D%E5%AE%89%E8%A3%85%E6%B8%B8%E6%88%8Fapk%E7%9B%B4%E6%8E%A5%E5%90%AF%E5%8A%A8%E6%B3%95…

web字体设置成平方字体_Web字体正确完成

web字体设置成平方字体When using web fonts we must carefully avoid its hidden pitfalls. To do this designers, frontend developers, DevOps, and authors each have a role to play in creating a great end-user experience.使用网络字体时&#xff0c;必须小心避免其隐…

Android客户端打包方案分享

基本介绍 Android应用的自动化打包是应用持续集成以及多渠道发布的基础。当前Android客户端自动化打包的主要有两种方式&#xff0c;Ant和Maven。两种方式本质上都是调用Android SDK里面提供的工具&#xff0c;不过各自有各自的特点。 1. Ant脚本 好处&#xff1a;开发成本较低…

sql注入修复方法是_旧的方法是修复我们可以看到的内容。

sql注入修复方法是When envisioning the futurestate of a company or a service, we’re usually faced with the challenge of designing for a customer that doesn’t exist yet. What do we mean by this? Well, they exist in the obvious sense, they’re just not ‘t…

library听证会_听证会

library听证会My Initial Experience with a Screen Reader我对屏幕阅读器的初步体验 As a new web developer, I have been learning to make my sites visually appealing but still be accessible, and all-in-all, it’s been going decent. I’ve been including cool ic…

jsoup测试例子

1、测试代码 import java.io.File; import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class Test { public static void main(String[] args) { Test t new Test(); t.parseUrl(); } publ…

ux和ui_他们说,以UX / UI设计师的身份加入一家初创公司。 他们说,这会很有趣。

ux和uiSure, working in a startup environment sounds fun. The stories of flexibility and freedom that it entails spark curiosity into people’s minds, making it enticing to explore a career in the startup scene. In reality, working in a startup just present…

程序员在囧途

程序员在囧途&#xff1a;http://www.shenyisyn.org/2013/05/21/cxyzhc.htm转载于:https://www.cnblogs.com/Qiaoyq/archive/2013/05/22/3092904.html

架构师之路 扩充字段_扩大您作为设计师的业务影响力的四个基础

架构师之路 扩充字段While catching up with my designer friends during these days of quarantine, a common topic surfaced in all our conversations despite the different countries, cultures, companies, seniority levels, and paths in the field: 在这些隔离日中与…

android之隐式intent调用

直接上代码 MainActivity.java 1 package com.example.test1;2 3 import android.app.Activity;4 import android.content.Intent;5 import android.net.Uri;6 import android.os.Bundle;7 import android.view.View;8 import android.view.View.OnClickListener;9 import andr…

webflow_Webflow是否适合开发人员? 我的经验

webflowThe biggest problem with site builders is the code they generate is usually garbage. As I’ve recently discovered, this isn’t the case with 网站建设者最大的问题是他们生成的代码通常是垃圾。 正如我最近发现的&#xff0c;情况并非如此 Webflow, and alth…

1.蛋疼上路

开博客了&#xff01; 感觉会是很花时间的事。。转载于:https://www.cnblogs.com/-dante-/archive/2013/05/26/3099789.html

您的UX库不只是书籍

hp ux 密码不过期Looking back on past self, one thing I wish I’d realised is the importance of keeping notes of everything.回顾过去的自我&#xff0c;我希望我意识到的一件事是记录所有事情的重要性。 This means everything interesting I’ve read and written; e…

编译器错误 CS1026

http://technet.microsoft.com/zh-cn/library/tc5zwdf7%28vvs.80%29转载于:https://www.cnblogs.com/Peter-Youny/archive/2013/05/26/3099808.html

交互设计精髓_设计空间的精髓

交互设计精髓重点 (Top highlight)什么是空间&#xff1f; (What is Space?) Space is the dimension of height, depth and width within which all things exist and move. Space or Empty space or White space or Negative space are alias given to describe intensional…

软件过程软件Scrum敏捷开发

在写这篇文章之前&#xff0c;xxx已经写过了几篇关于改软件过程软件主题的文章,想要了解的朋友可以去翻一下之前的文章 1、什么是软件进程? 软件进程是为了建造高质量软件所需实现的任务的框架,即形成软件产品的一系列步骤,它划定了实现各项任务任务步骤,包括了中间产品、资源…

ux和ui_UI和UX设计人员的47个关键课程

ux和ui重点 (Top highlight)This is a mega-list of the most critical knowledge for UI, UX, interaction, or product designers at any level.这是所有级别的UI&#xff0c;UX&#xff0c;交互或产品设计人员最关键的知识的大清单。 Many of these lessons are also appli…