交换函数

来源:互联网 发布:现在在做淘宝客晚吗 编辑:程序博客网 时间:2024/04/30 10:48

由于c函数中是传值的,所以交换值的函数必须使用指针,试着提出一种以结构形式的函数

只是一个初步的函数,尚未编译运行通过,待完成。

/* 2016/5/8*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>void moveZeroes(int* nums, int numsSize);typedef struct{int x;int y;}TREE;TREE swap(TREE *sTin);int main (){TREE *sNode;TREE *sNewnode;*sNode = {2, 3};printf("old is %d, %d\n", sNode->x, sNode->y);*sNewnode = swap(*sNode);printf("new is %d, %d\n", sNewnode->x, sNewnode->y);system("pause");return 0;}TREE swap(TREE *sTin){int temp;temp = sTin->x;sTin->x = sTin->y;sTin->y = sTin->x;return sTin;}


0 0
原创粉丝点击