函数题:链表-创建链表
本题要求实现一个函数,建立一个链表,返回头指针(即头节点地址)
head是链表的头指针,链表上节点的定义如下:
struct node
{char ch;
struct node * next;}
链表上节点的数据成员ch按顺序赋值0,1,2,3......至n-1
### 函数接口定义:
c++
在这里描述函数接口。例如:
struct node *setlink(int n);
n 是节点个数,返回值是头指针
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
#include<stdlib.h>
struct node
{int ch;
struct node * next;};
int countnode(struct node * head);//此函数功能遍历链表,已定义
struct node *setlink(int N);//在代码区定义此函数
int main()
{
int i,N;
struct node *head;
scanf("%d",&N);
head=setlink(N);
printf("%d", countnode(head));
return 0;
}
/* 请在这里填写答案 */
### 输入样例:
在这里给出一组输入。例如:
in
5
### 输出样例:
在这里给出相应的输出。例如:
out
10
答案:若无答案欢迎评论
head是链表的头指针,链表上节点的定义如下:
struct node
{char ch;
struct node * next;}
链表上节点的数据成员ch按顺序赋值0,1,2,3......至n-1
### 函数接口定义:
c++
在这里描述函数接口。例如:
struct node *setlink(int n);
n 是节点个数,返回值是头指针
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
#include<stdlib.h>
struct node
{int ch;
struct node * next;};
int countnode(struct node * head);//此函数功能遍历链表,已定义
struct node *setlink(int N);//在代码区定义此函数
int main()
{
int i,N;
struct node *head;
scanf("%d",&N);
head=setlink(N);
printf("%d", countnode(head));
return 0;
}
/* 请在这里填写答案 */
### 输入样例:
在这里给出一组输入。例如:
in
5
### 输出样例:
在这里给出相应的输出。例如:
out
10
答案:若无答案欢迎评论