⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkdemo.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates the fundamentals of using */
/* a linked list. */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* The list data structure. */
struct data {
    char name[20];
    struct data *next;
};

/* Define typedefs for the structure */
/* and a pointer to it. */
typedef struct data PERSON;
typedef PERSON *LINK;

int main( void )
{
  /* Head, new, and current element pointers. */
  LINK head = NULL;
  LINK new = NULL;
  LINK current = NULL;

  /* Add the first list element. We do not */
  /* assume the list is empty, although in */
  /* this demo program it always will be. */

  new = (LINK)malloc(sizeof(PERSON));
  new->next = head;
  head = new;
  strcpy(new->name, "Abigail");

  /* Add an element to the end of the list. */
  /* We assume the list contains at least one element. */

  current = head;
  while (current->next != NULL)
  {
    current = current->next;
  }

  new = (LINK)malloc(sizeof(PERSON));
  current->next = new;
  new->next = NULL;
  strcpy(new->name, "Carolyn");

  /* Add a new element at the second position in the list. */
  new = (LINK)malloc(sizeof(PERSON));
  new->next = head->next;
  head->next = new;
  strcpy(new->name, "Beatrice");

  /* Print all data items in order. */
  current = head;
  while (current != NULL)
  {
    printf("\n%s", current->name);
    current = current->next;
  }

  printf("\n");

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -