Recursive exercise--recursive method for inserting data

Source: Internet
Author: User



#include <iostream> #include <vector>using namespace std;void print (char*,int); void Insertintovector (char *,int); void Printvector (); void insertion (char c,int start, int end); vector<char>vecchar;int Main (int argc, char*    Argv[]) {char str[1000];    int Len;    Vecchar.clear ();            while (1) {cout<<endl;            Fgets (str,sizeof (str), stdin);            len = strlen (str);            Print (Str,len);                        Insertintovector (Str,len);                Printvector ();    } return 0;     }void Print (char* str,int N) {for (int i=0; i<n; i++) {cout<<str[i];     }}void insertintovector (char* str,int n) {int vectorsize;     cout << str <<endl;             for (int i=0; i<n; i++) {vectorsize = Vecchar.size ();             cout<< vectorsize <<endl;             if (vectorsize <1) {vecchar.push_back (str[i]); } else if(Str[i] <= VECCHAR[VECTORSIZE/2])             {insertion (STR[I],0,VECTORSIZE/2);                              } else {insertion (str[i],vectorsize/2+1,vectorsize); }}}void Insertion (char c,int start, int end) {//cout << "start:" <<start<< "End:" <<end<     <endl;         if (start = = end) {Vector<char>::iterator it;         it = Vecchar.begin () +start;         if (c<*it) Vecchar.insert (IT,C);            else//Vecchar.insert (IT+1,C);          /* while () {} */return;     } int mid = (start+end)/2;     if (c <= Vecchar[mid]) {insertion (C,START,MID);     } else {insertion (c,mid+1,end);     }}void printvector () {int size = Vecchar.size ();     cout << Size <<endl;     cout << "Print vector" <<endl; for (int i=0; i<size;     i++) {cout<<vecchar[i]; }//cout <<endl<< "+++++==++++=" &LT;&LT;ENDL;}


Recursive exercise--recursive method for inserting data

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.