diguilianbiao.cpp
来自「关于数据结构的各章节的c原代码实现」· C++ 代码 · 共 52 行
CPP
52 行
// diguilianbiao.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
struct list_node
{
int data;
struct list_node *next;
};
typedef struct list_node node;
typedef node* link;
link creatlist(int *array,int len,int pos)
{
link newnode;
if(pos==len){
return NULL;
}
else
{
newnode=(link)malloc(sizeof(node));
if(!newnode)
return NULL;
newnode->data=array[pos];
newnode->next=creatlist(array,len,++pos);
return newnode;
}
}
void printlist(link head)
{
if (head!=NULL)
{
printf("%3d",head->data);
printf("\n");
printlist(head->next);
}
}
int main(int argc, char* argv[])
{
int array[6]={4,5,6,2,9,7};
link head;
head=creatlist(array,6,0);
printlist(head);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?