#include<stdio.h>
int main()
{
inti;
for(i=1i<=8i++)
printf("1234567890\n");
return0;
}
扩展资料:
for 循环语句的一般形式为:
for (表达式1; 表达式2; 表达式3)
{
语句;
}
首先要强调两点:
1) 表达式1、表达式2和表达式3之间是用分号;隔开的,千万不要写成逗号。
2) for(表达式1;表达式2;表达式3)的后面千万不要加分号,很多新手都会犯这种错误——会情不自禁地在后面加分号。
因为 for 循环只能控制到其后的一条语句,而在C语言中分号也是一个语句——空语句。所以如果在后面加个分号,那么 for 循环就只能控制到这个分号,下面大括号里面的语句就不属于 for 循环了。
int*pA=A[0][0]所以
i*3*4+j*4+k
由于是int指针
k增加1
就是
指针移动一个int
4字节
j增加1
就是移动
4个int
16
个字节
i增加
i
就是移动
i*3*4
=
12个
int
48字节
也就是
3位数
就是这样
有疑问请追问
满意记得采纳
//输入先序扩展序列: 6 5 0 0 7 0 0//后序遍历序列: 5 7 6
// 6
// / \
// 5 7
// / \ / \
// 0 0 0 0
//输入先序扩展序列: 4 2 1 0 0 3 0 0 5 0 6 0 0
//后序遍历序列: 1 3 2 6 5 4
//
// 4
// / \
// 2 5
// / \ / \
// 1 3 0 6
// / \ / \ / \
// 0 0 0 0 0 0
#include<stdio.h>
#include<stdlib.h>
#define max 100 //20 //栈的大小
struct bitree //二叉树的结构体
{
int data
struct bitree *llink //左分支
struct bitree *rlink //右分支
}
struct stack_post //栈的结构体 [用于后序遍历]
{
struct bitree *bt //指向二叉树
int leftOrRight //当前节点是哪个分支,1=左分支 0=右分支
}
struct stack_post sk[max] //全局变量:栈(用于后序遍历)
//void build(struct bitree *n)
//创建二叉树: 先序扩展序列 + 递归法
void build(struct bitree **n)
{
//注:struct bitree **n 是指针的指针
int ch
scanf("%d",&ch)
if(ch==0)
{
*n=NULL
}
else
{
*n=(struct bitree *)malloc(sizeof(struct bitree))
if(*n == NULL)
{
printf("\nMemory overflow!\n")
exit(1)
}
(*n)->data=ch
build(&((*n)->llink))
build(&((*n)->rlink))
}
//原代码
/*
n=(struct bitree *)malloc(sizeof(struct bitree))
scanf("%d",&ch)
if(ch==0)
n=NULL
else
{
if(!(n=(struct bitree *)malloc(sizeof(struct bitree))))
{
return
}
n->data=ch
build(n->llink)
build(n->rlink)
}
*/
}
//后序遍历序列(非递归)
void Post_Order(struct bitree *n)
{
struct bitree *p=NULL
////struct stack_post sk[max] //全局变量:栈(用于后序遍历)
int top=0 //栈顶为0, top=1用于存放第1个数据
int leftOrRight //当前节点是哪个分支,1=左分支 0=右分支
struct bitree *tmpTree
if(n == NULL) return
p = n //当前二叉树的节点
leftOrRight = 1 //1=左分支(默认从左分支开始遍历)
while(p != NULL)
{
if(p->llink != NULL) //有左分支,当前节点入栈
{
top++
sk[top].bt=p
sk[top].leftOrRight=leftOrRight
p = p->llink
leftOrRight = 1
}
else if(p->rlink != NULL) //有右分支,当前节点入栈
{
top++
sk[top].bt=p
sk[top].leftOrRight=leftOrRight
p = p->rlink
leftOrRight = 0
}
else //该节点是"叶子"
{
printf("%d ",p->data)
while(1) //处于"回溯"状态
{
tmpTree=sk[top].bt //看[栈顶]
if(tmpTree==NULL) //[栈]已经没有数据
{
p=NULL //整个遍历过程结束,退出循环
break
}
if(leftOrRight == 1) //处于"左分支"回溯
{
if(tmpTree->rlink == NULL)//[栈顶]的节点没有右分支,出栈,打印
{
p=sk[top].bt
leftOrRight=sk[top].leftOrRight
top--
printf("%d ",p->data)
//仍然处于"回溯"状态
}
else //[栈顶]的节点有右分支,不出栈,右分支成为当前节点
{
p=tmpTree->rlink
leftOrRight=0 //设置当前处于右分支
break //退出"回溯"状态
}
}
else //处于"右分支"回溯
{
//[栈]有节点,出栈,打印
p=sk[top].bt
leftOrRight=sk[top].leftOrRight
top--
printf("%d ",p->data)
//仍然处于"回溯"状态
}
} //while(1)结束
} //if(p->llink != NULL)else结束
} //while(p != NULL)结束
//栈顶top=0,说明[栈]已经没有数据
printf("\n核对,栈顶 top = %d\n",top)
}
//有错误
//原代码,后序遍历序列(非递归)
/*
void postorder(struct bitree *n)
{
struct bitree *p,*q
int i
p=(struct bitree *)malloc(sizeof(struct bitree))
p=n
q=(struct bitree *)malloc(sizeof(struct bitree))
struct bitree *s[max]
for(i=0i<maxi++)
{
s[i]=(struct bitree *)malloc(sizeof(struct bitree))
}
int top=-1
do
{
while(p!=NULL)
{
if(p->rlink!=NULL)
{
top++
s[top]=p->rlink
}
p=p->llink
}
p=s[top]
top--
if(p->rlink==NULL||p->rlink==q)
{
printf("%d ",p->data)
q=p
p=NULL
}
else
p=p->rlink
}while(p!=NULL||top!=-1)
}
*/
//后序遍历序列(递归) [用于对比测试]
void postTest(struct bitree *n)
{
if(n!=NULL)
{
postTest(n->llink)
postTest(n->rlink)
printf("%d ",n->data)
}
}
int main()
{
struct bitree *n
//原代码n=(struct bitree *)malloc(sizeof(struct bitree))
printf("Input the preorder-numbers of the tree('0' for NULL):\n")
//原代码build(n)
build(&n)
printf("\nPostorder is below: ")
//原代码postorder(n) //后序遍历序列(非递归)
Post_Order(n) //后序遍历序列(非递归)
printf("\n后序遍历序列(递归): ")
postTest(n) //用于对比测试
printf("\n")
return 0
}