首页 > 其他 > 详细

Cracking the Coding Interview 8.5

时间:2014-08-21 13:06:34      阅读:377      评论:0      收藏:0      [点我收藏+]

Implement an algorithm to print all valid combinations of n-pairs of parentheses

 

#include<stdio.h>

void f(int idx,int left,int right,char *buf)
{
    if(left == 0 && right == 0)
    {
        buf[idx] = \0;
        printf("%s\n",buf);
    }
    if(left>0)
    {
        buf[idx]=(;
        f(idx+1,left-1,right,buf);
    }
    if(right>left)
    {
        buf[idx]=);
        f(idx+1,left,right-1,buf);
    }
}

int main()
{
    int n=1;
    char *buf = new char[n+1];
    f(0,n,n,buf);
    return 0;
}

 

Cracking the Coding Interview 8.5,布布扣,bubuko.com

Cracking the Coding Interview 8.5

原文:http://www.cnblogs.com/johnsblog/p/3926742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!