C + + Language practice Book

Source: Internet
Author: User

  the/************************************** integer corresponds to the number of number 1 in the number of binary binary strings  2016-10-24  liukun******************* /#include <stdio.h>//#include <math.h>//integer corresponds to the number of digits 1 in the number binary string int binary1counter ( int n) {    //if (n<0) return-1;    int i;    int binalength = ceil (log2 (n));    int counter1=0;    for (i=0;i<32;++i)  //for (i=0;i<binalength;++i)    {        if (n & 1!=0) counter1++;        n = n>>1;    }    printf ("%d\n", counter1);    return 1;} int main () {    binary1counter ( -21);    return 0;}

  

/**************************************** print Yang Hui triangle date:2016-10-15 writer:liu kun Reference: Data structure Yin ********* /#include <iostream> #include <iomanip> #include "queue.h" using    namespace std;//control digital interval char blank[3+1] = ""; void Yangvi (int n) {Queue q; EnQueue (q,1);    EnQueue (q,1); int i,j;    Qelemtype s=0,t;        for (i=1;i<=n;i++) {cout<<endl;        The starting position of each line is typeset for (int bl_count=0;bl_count<n-i;bl_count++) cout<<blank;        EnQueue (q,0);            for (j=1;j<=i+2;j++)//Line I i+2 coefficients, including a 0 {DeQueue (q,t); EnQueue (q,s+t);            Calculate the next row coefficients to merge into Team s=t;        if (j!=i+2) cout<<setw (sizeof (blank)-1) <<s<<blank;    }}};int Main () {Yangvi (10);  return 0;} > Queue.h#ifndef queue_h_included#define queue_h_included#define MAXSIZE 500typedef int qelemtype;typedef struct    queue{int maxsize=maxsize; Qelemtype *data=new qelemtype[MaxSize];    int front=0; int Rear=front;} Queue;void initqueue (queue &q); int EnQueue (Queue &q, Qelemtype x) {//check full if ((q.rear+1)%q.maxsize==q.f    Ront) {return 0;        } else{q.data[q.rear]=x;        Q.rear = (q.rear+1)%q.maxsize;    return 1;    }}int DeQueue (Queue &q,QElemType& x) {//check empty, ERROR code 1 if (Q.rear==q.front) return 0;        else{x = Q.data[q.front];        Q.front= (q.front+1)%q.maxsize;    return 1;    }}int queueempty (Queue &q) {if (Q.rear==q.front) return 1; else return 0;} Reference as address value int queuefull (Queue &q) {return (q.rear+1)%q.maxsize==q.front;} int queuesize (queue& q) {return (Q.rear+q.maxsize-q.front)%q.maxsize;}   #endif//queue_h_included

  

C + + Language practice Book

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.