GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — C-_Note/C++_course.cpp at main · ConquerCommand/C-_Note Expand file tree/ Copy pathC++_course.cppMore file actions 1774 lines (1712 loc) · 35.7 KB / Copy pathC++_course.cppFile metadata and controls1774 lines (1712 loc) · 35.7 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 # -*- coding: utf-8 -*- """C++_course.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1rBj1UVXLSGdK1Jhb3N24NbBPcgbT7cnN """ #include <iostream> using namespace std; int main() { std::cout << "Hello World!" << endl; //comment int age =10; char grade = 'A'; float PI = 3.14f; double price = 100.99; bool issafe = true; cout<<age<<endl; int value = grade; cout<<grade<<endl; cout<<value<<endl; int newprice=(int)price; cout<<newprice<<endl; int x; cout<<"input:"<<endl; //cin>>x; //cout<<x; int a=10,b=5; cout<<(a+b) <<endl<< (a-b)<<endl<< (a*b)<<endl<< (a/b)<<endl<< (a%b)<<endl; //==,!=,<,>,<=,>= //||(or),&&(and),!(not) int a1=10; int b1=a1++; cout<<a1<<endl<<b1<<endl; int c1=++a1; cout<<a1<<endl<<c1<<endl; int a2=10; int b2=a2--; cout<<a2<<endl<<b2<<endl; int c2=--a2; cout<<a2<<endl<<c2<<endl; return 0; } int main(){ int n1=4 long int n2=8 short int n3=2 long long int n4=8 signed int n5=4 unsigned int n5=-4 } int main() { int a=0; int n=0; if (a>100){ cout<<"100"<<endl; }else if(a==50){ cout<<"50"<<endl; }else{ cout<<"0"<<endl; } cout<<(n>=0 ? "p":"n")<<endl; return 0; } int main() { int c= 1; while(c<5){ cout<<c; c++; } cout<<endl; for (int i=1;i<=7;i++){ cout<<i; if (i==5){ break; } } cout<<endl; do{ cout<<c; c++; }while(c<10); cout<<endl; return 0; } int main() { int n = 4; for ( int i=0; i<n; i++) { char ch = 'A'; for ( int j=0; j<n; j++) { cout << ch; ch = ch + 1; } cout<< endl; } return 0; } int main() { int n = 6; for( int i=0; i<n; i++) { for(int j=0; j<i+1; j++) { cout<<"*" ; } cout<< endl; } return 0; } int v3(){ cout<<"hello\n"; return 3; } double dd(double a, double b){ double s=a+b; return s; } void t(){ cout<<"hello\n"; } int main() { int v=v3(); cout<<v<<endl; cout<<dd(4,5)<<endl; t(); return 0; } //pass by value int sum_v(int a, int b){ a += 10;//15 b += 10;//14 return a+b;//29 } //pass by reference int sum_r(int &a, int &b){ a+=10;//15 b+=10;//14 return a+b;//29 } int main(){ int a=5 , b=4; cout << sum_v(a, b) << endl; cout << a << endl; cout << b << endl; cout << sum_r(a, b) << endl; cout << a << endl; cout << b << endl; return 0; } //bitwise operator:- //&(and) |(or) ^(xor) <<(left shift) >>(right shift) //operator precendenc:- //(! ++ --) (* / %) (+ -) (< <= > >=) (== !=) (&&) (||) (=) int main(){ int n1=4 long int n2=8 short int n3=2 long long int n4=8 signed int n5=4 unsigned int n5=-4 } int main(){ int arr[5]={1,2,3,4,5}; string ar1[5]={"a","b","c"}; ar1[3]="d" return 0; } #include <iostream> #include <vector> using namespace std; int main() { vector<int> vec={1,2,3}; vector<int> v1(5,0); vector<int> v2(vec); //vec.size().capacity().front().back().at() //vec.push_front()push_back().pop_back().pop_front().emplace_back().emplace_front() //vec.erase(vec.begin()+pos).erase(start,end) //vec.insert(vec.begin()+pos).insert(pos,val) //vec.clear().empty().resize().swap() //sort(vec.begin(),vec.end()) reverce(vec.begin(),vec.end()) for (int i :v1){ cout<<i<<endl;} vector<int>::iterator it; for(it=vec.begin();it!=vec.end();it++){ cout<<*(it)<<endl;} vector<int>::reverse_iterator itr; for(itr=vec.rbegin();itr!=vec.rend();itr++){ cout<<*(itr)<<' ';} for(auto ita=vec.begin();ita!=vec.end();ita++){ cout<<*(ita)<<' ';} } #include <iostream> #include <vector> using namespace std; int main(){ int a =10; int* ptr=&a; int** parptr=&ptr; cout<<&a<<endl; cout<<ptr<<endl; cout<<&ptr<<endl; cout<<parptr<<endl; cout<<*(&a)<<endl; cout<<*(ptr)<<endl; cout<<**(parptr)<<endl; int** nptr=NULL; cout<<nptr<<endl; return 0; } #include <iostream> #include <vector> using namespace std; void unchange(int a) // pass by value {a=20;} void change(int* ptr) // pass by reference {*ptr=20;} int main(){ int a=10, b=15; int arr[]={1,2,3,4,5}; unchange(a); cout<<a<<endl; change(&a); cout<<a<<endl; int* ptr1=&b; ptr1=&a; //arr=&a(doesnt work) //arrays are constent pointter cout<<ptr1<<endl; ptr1++; // 4 bits for int dtype cout<<ptr1<<endl; cout<<arr<<endl; cout<<*arr<<endl; cout<<*arr+1<<endl; int* ptr2=ptr1+1; cout<<ptr2-ptr1<<endl; cout<<(ptr2!=ptr1)<<endl; // & used for address // * used for dereference return 0; } #include <iostream> #include <vector> #include <list> using namespace std; int main(){ list<int>l{1,2,3,4,5}; //list=doubly linked list //l.push_front().push_back().pop_back().pop_front().emplace_front().emplace_back() //l.size().insert().erase().clean().front().back().begin().end().rbegin().rend() for (int i :l){ cout<<i<<endl;} return 0; } #include <iostream> #include <vector> #include <deque> using namespace std; int main() { deque<int>d{1,2,3,4,5}; //deque=dynamic array //d.push_front().push_back().pop_back().pop_front().emplace_front().emplace_back() //d.size().insert().erase().clean().front().back().begin().end().rbegin().rend() for (int i :d){ cout<<i<<endl;} return 0; } #include <iostream> #include <vector> using namespace std; int main() { pair<char,int>p={'a',1}; cout<<p.first<<p.second<<endl; pair<int,pair<int,int>>pp={1,{2,3}}; cout<<pp.first<<pp.second.first<<endl; vector<pair<int,int>> v={{1,2},{2,3},{3,4}}; v.push_back({4,5});//insert v.emplace_back(5,6);//inplace object create (faster) for (auto vp:v){ cout<<vp.first<<vp.second<<endl;} return 0; } #include <iostream> #include <vector> #include <list> #include <deque> #include <stack> using namespace std; int main() { stack<int>s; //s.push().emplace().top().pop().size().empty().swap() s.push(1); s.push(2); s.push(3); s.push(4); s.push(5); while(!s.empty()){ cout<<s.top()<<endl; s.pop();} return 0; } #include <iostream> #include <vector> #include <list> #include <deque> #include <queue> using namespace std; int main() { queue<int>q; //q.push().emplace().front().pop().size().empty().swap() q.push(1); q.push(2); q.push(3); q.push(4); q.push(5); while(!s.empty()){ cout<<s.front()<<endl; s.pop();} priority_queue<int,vector<int>,greater<int>>pq; pq.push(2); pq.push(1); pq.push(3); while(!pq.empty()){ cout<<pq.top()<<endl; pq.pop();} return 0; } #include <iostream> #include <vector> #include <list> #include <deque> #include <stack> #include <queue> #include <map> #include <unorder_map> using namespace std; int main() { map<string,int>m; m["a"]=1; m.insert({"b",2}); m.emplace("c",3); //m.count().find().size().empty().erase() //O(log(n)) multimap<string,int>mm; //multimap can store samething //mm.erase()->erase all samething //mm.erase(mm.find())->erase onething mm.insert({"a",1}); mm.emplace("a",1); for(auto i:mm){ cout<<i.first<<i.second<<endl;} unordered_map<string,int>um; //not stored in order of key //fast O(1) um["c"]=3; um.insert({"a",1}); um.emplace("b",2); for(auto i:um){ cout<<i.first<<i.second<<endl;} return 0; } #include <iostream> #include <vector> #include <list> #include <deque> #include <stack> #include <queue> #include <map> #include <unordered_map> #include <set> #include <unordered_set> using namespace std; int main() { set<int>s={3,2,1}; //unique value,order,O(logn) //s.insert().emplace().merge().size().count().find() //s.erase().empty().begin().end() s.insert(1); s.emplace(1); cout<<*(s.lower_bound(2))<<endl; //gives that one if not there then upper to that,no upper then last one cout<<*(s.upper_bound(10))<<endl; //gives upper one if not there then last one for(auto i:s){ cout<<i<<endl;} multiset<int>ms={3,2,1}; //not unique,order,O(logn) unordered_set<int>us={3,2,1}; //unique,not order,no lb or ub,O(1) return 0; } #include <iostream> #include <vector> #include <list> #include <deque> #include <stack> #include <queue> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <algorithm> using namespace std; bool comparator(pair<int,int>a,pair<int,int>b){ if (a.second<b.second) return true; else return false;} int main(){ vector<pair<int,int>> v={{2,4},{1,5},{3,3},{5,1},{4,2}}; sort(v.begin(),v.end()); for (auto i:v){ cout<<i.first<<' '<<i.second<<endl;} sort(v.begin(),v.end(),greater<pair<int,int>>()); sort(v.begin(),v.end(),comparator);//same work for (auto i:v){ cout<<i.first<<' '<<i.second<<endl;} //reverse(),next_permutation(),prev_permutation() //swap(),min(),max(),max_element(),min_element() //binary_search(),builtin_popcount() return 0; } #include <iostream> using namespace std; void pn(int n){ cout<<' '<<n<<' '; if(n==1){ cout<<" #"<<n<<"# "; cout<<" *"<<n<<"* "; return; } cout<<" #"<<n<<"# "; pn(n-1); cout<<" *"<<n<<"* "; } int main(){ pn(5); return 0; } #include <iostream> #include <vector> using namespace std; void bt(vector<int> &arr, vector<int> &ans,int h){ if(h==arr.size()){ for(int i:ans){ cout<<i<<" "; } cout<<endl; return; } ans.push_back(arr[h]); bt(arr,ans,h+1); ans.pop_back(); bt(arr,ans,h+1); } int main(){ vector<int> arr={1,2,3}; vector<int> ans; bt(arr,ans,0); return 0; } #include <iostream> using namespace std; class cc{ private: string apv; string bpv; public: string apb; string bpb; string cpb; cc(){//non-parameterized constructor cout<<"this in is non-parameterized constructor"<<endl; this->cpb="np-cb1"; } cc(string c){//parameterized constructor cout<<"this in is parameterized constructor"<<endl; this->cpb=c; } cc(cc &orgObj){//copy constructor cout<<"this in is copy constructor"<<endl; this->cpb=orgObj.cpb; } void method1(string napb){ this->apb=napb; } //sets a private varible void setter(string napv){ this->apv=napv; } //gets a private varible string getter(){ return this->apv; } }; int main(){ cc c1; c1.apb="ab1"; c1.bpb="bb1"; cout<<c1.apb<<endl; c1.method1("ab2"); cout<<c1.apb<<endl; c1.setter("av1"); cout<<c1.getter()<<endl; cout<<c1.cpb<<endl; cc c2("cb1"); cout<<c2.cpb<<endl; //defult copy constructor //custom copy constructor cc c3(c2); cout<<c3.cpb<<endl; return 0; } #include <iostream> using namespace std; class cc{ private: string apv; string bpv; public: string apb; string bpb; string cpb; string *shpbPtr;//shallow copy string *depbPtr;//deep copy cc(){//non-parameterized constructor cout<<"this in is non-parameterized constructor"<<endl; this->cpb="np-cb1"; } cc(string c){//parameterized constructor cout<<"this in is parameterized constructor"<<endl; this->cpb=c; shpbPtr=new string; *shpbPtr="sb1"; depbPtr=new string; *depbPtr="db1"; } cc(cc &orgObj){//copy constructor cout<<"this in is copy constructor"<<endl; this->cpb=orgObj.cpb; this->shpbPtr=orgObj.shpbPtr; depbPtr=new string; *depbPtr=*orgObj.depbPtr; } ~cc(){//destructor cout<<"this delets constructor"<<endl; delete shpbPtr; delete depbPtr; } void method1(string napb){ this->apb=napb; } //sets a private varible void setter(string napv){ this->apv=napv; } //gets a private varible string getter(){ return this->apv; } }; int main(){ cc c1; c1.apb="ab1"; c1.bpb="bb1"; cout<<c1.apb<<endl; c1.method1("ab2"); cout<<c1.apb<<endl; c1.setter("av1"); cout<<c1.getter()<<endl; cout<<c1.cpb<<endl; cc c2("cb1"); cout<<c2.cpb<<endl; //defult copy constructor //custom copy constructor cc c3(c2); cout<<c3.cpb<<endl; //shallow copy cout<<*c3.shpbPtr<<endl; *c3.shpbPtr="sb2"; cout<<*c2.shpbPtr<<endl;//changed cout<<*c3.shpbPtr<<endl; //deep copy cout<<*c3.depbPtr<<endl; *c3.depbPtr="db2"; cout<<*c2.depbPtr<<endl;//unchanged cout<<*c3.depbPtr<<endl; return 0; } //hybride inheritance //multilavel inheritance //multipath inheritance class gpa{//grand parent class public: string gpa1in; }; //hierarchical inheritance class pa1:virtual public gpa{//parent class public: string pa1in; }; class pa2:virtual public gpa{//parent class public: string pa2in; }; //multiple inheritance class chi:public pa1,public pa2{//child class public: string ch1in; }; //inheriting constructor class con_pa{ public: string con; con_pa(string c){ this->con=c; } }; class con_ch:public con_pa{ public: con_ch(string c):con_pa(c){ this->con=c; } }; int main(){ chi kid1; kid1.gpa1in="gpa1in_ch_1"; cout<<kid1.gpa1in<<endl; //polymorphism constructor con_ch conc1("con1"); cout<<conc1.con<<endl; return 0; } class con_pa{ public: string con; con_pa(string c){ this->con=c; } void same_method(){ cout<<"parent's met"<<endl; } virtual void vir_fun(){ cout<<"parent's vf"<<endl; } }; class con_ch:public con_pa{ public: con_ch(string c):con_pa(c){ this->con=c; } void same_method(){ cout<<"child's met"<<endl; } void same_method(string x){ cout<<"string"<<endl; } void same_method(int x){ cout<<"integer"<<endl; } virtual void vir_fun(){ cout<<"child's vf"<<endl; } }; int main(){ //polymorphism constructor con_ch conc1("con1"); cout<<conc1.con<<endl; //polymorphism method conc1.same_method("10"); conc1.same_method(10); //overriding conc1.same_method(); //virtual function conc1.vir_fun(); return 0; } class abst{//abstract class public: //pure virtual function virtual void pvf() = 0; }; class aa:public abst{//derived class public: //forced implement void pvf() override{ cout<<"override"<<endl; } }; int main(){ //abstraction abst* a1= new aa(); a1->pvf(); return 0; } class sta{ public: //shared by all objects //static Variables static int count; string s; sta(string s){ cout<<"construct"<<endl; this->s=s; count++; } ~sta(){ cout<<s<<endl; } }; //initialize static variable outside class int sta::count=0; int main(){ //static keyword sta st1("destruct-st1"); //static object static sta st2("destructor-st2"); cout<<sta::count<<endl; cout<<"end main"<<endl; return 0; } #include <iostream> using namespace std; class cc{ private: string apv; string bpv; public: string apb; string bpb; string cpb; string *shpbPtr;//shallow copy string *depbPtr;//deep copy cc(){//non-parameterized constructor cout<<"this is default constructor"<<endl; this->cpb="np-cb1"; } cc(string c){//parameterized constructor cout<<"this is parameterized constructor"<<endl; this->cpb=c; shpbPtr=new string; *shpbPtr="sb1"; depbPtr=new string; *depbPtr="db1"; } cc(cc &orgObj){//copy constructor cout<<"this is copy constructor"<<endl; this->cpb=orgObj.cpb; this->shpbPtr=orgObj.shpbPtr; depbPtr=new string; *depbPtr=*orgObj.depbPtr; } ~cc(){//destructor cout<<"this delets constructor"<<endl; delete shpbPtr; delete depbPtr; } void method1(string napb){ this->apb=napb; } //sets a private varible void setter(string napv){ this->apv=napv; } //gets a private varible string getter(){ return this->apv; } }; //hybride inheritance //multilavel inheritance //multipath inheritance class gpa{//grand parent class public: string gpa1in; }; //hierarchical inheritance class pa1:virtual public gpa{//parent class public: string pa1in; }; class pa2:virtual public gpa{//parent class public: string pa2in; }; //multiple inheritance class ch1:public pa1,public pa2{//child class public: string ch1in; }; //inheriting constructor class con_pa{ public: string con; con_pa(string c){ this->con=c; } void same_method(){ cout<<"parent's met"<<endl; } virtual void vir_fun(){ cout<<"parent's vf"<<endl; } }; class con_ch:public con_pa{ public: con_ch(string c):con_pa(c){ this->con=c; } void same_method(){ cout<<"child's met"<<endl; } void same_method(string x){ cout<<"string"<<endl; } void same_method(int x){ cout<<"integer"<<endl; } virtual void vir_fun(){ cout<<"child's vf"<<endl; } }; class abst{//abstract class public: //pure virtual function virtual void pvf() = 0; }; class aa:public abst{//derived class public: //forced implement void pvf() override{ cout<<"override"<<endl; } }; class sta{ public: //shared by all objects //static Variables static int count; string s; sta(string s){ cout<<"construct"<<endl; this->s=s; count++; } ~sta(){ cout<<s<<endl; } }; //initialize static variable outside class int sta::count=0; int main(){ cc c1; c1.apb="ab1"; c1.bpb="bb1"; cout<<c1.apb<<endl; c1.method1("ab2"); cout<<c1.apb<<endl; c1.setter("av1"); cout<<c1.getter()<<endl; cout<<c1.cpb<<endl; cc c2("cb1"); cout<<c2.cpb<<endl; //defult copy constructor //custom copy constructor cc c3(c2); cout<<c3.cpb<<endl; //shallow copy cout<<*c3.shpbPtr<<endl; *c3.shpbPtr="sb2"; cout<<*c2.shpbPtr<<endl;//changed cout<<*c3.shpbPtr<<endl; //deep copy cout<<*c3.depbPtr<<endl; *c3.depbPtr="db2"; cout<<*c2.depbPtr<<endl;//unchanged cout<<*c3.depbPtr<<endl; ch1 kid1; kid1.gpa1in="gpa1in_ch_1"; cout<<kid1.gpa1in<<endl; //polymorphism constructor con_ch conc1("con1"); cout<<conc1.con<<endl; //polymorphism method conc1.same_method("10"); conc1.same_method(10); //overriding conc1.same_method(); //virtual function conc1.vir_fun(); //abstraction abst* a1= new aa(); a1->pvf(); //static keyword sta st1("destruct-st1"); //static object static sta st2("destructor-st2"); cout<<sta::count<<endl; cout<<"end main"<<endl; return 0; } #include <iostream> using namespace std; class Node{ public: int data; Node* next; Node(int val){ data=val; next=nullptr; } }; class List{ Node* head; Node* tail; public: List(){ head=tail=nullptr; } void printLL(){ Node* temp=head; while(temp!=nullptr){ cout<<temp->data<<"->"; temp=temp->next; } cout<<"null"<<endl; } void push_front(int val){ Node* newNode= new Node(val); if(head==nullptr){ head=tail=newNode; return; }else{ newNode->next=head; head=newNode; } } void push_back(int val){ Node* newNode= new Node(val); if(tail==nullptr){ head=tail=newNode; return; }else{ tail->next=newNode; tail=newNode; } } void insert(int val, int pos){ if(pos<0){ cout<<"invalid pos\n"; return; } if(pos==0){ |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |