C++ Contoh Linklist
#include <iostream>
#include <list>
#include <iterator>
#include <algorithm>
#include <conio.h>
using namespace std;
int main()
{
list<int> intList1, intList2, intList3, intList4;
ostream_iterator<int> screen(cout," ");
intList1.push_back(23);
intList1.push_back(58);
intList1.push_back(58);
intList1.push_back(58);
intList1.push_back(36);
intList1.push_back(15);
intList1.push_back(93);
intList1.push_back(98);
intList1.push_back(58);
cout<<"Line 12: intList1: ";
copy(intList1.begin(),intList1.end(),screen);
cout<<endl;
intList2 = intList1;
cout<<"Line 16: intList2: ";
copy(intList2.begin(),intList2.end(),screen);
cout<<endl;
intList1.unique();
cout<<"Line 20: Sesudah dihapus konsekutifnya, "
<<"duplikat,"<<endl
<<" intList1: ";
copy(intList1.begin(),intList1.end(),screen);
cout<<endl;
intList2.sort();
cout<<"Line 24: Sesudah dipilih, intList2: ";
copy(intList2.begin(),intList2.end(),screen);
cout<<endl;
intList3.push_back(13);
intList3.push_back(23);
intList3.push_back(25);
intList3.push_back(136);
intList3.push_back(198);
cout<<"Baris 32: intList3: ";
copy(intList3.begin(),intList3.end(),screen);
cout<<endl;
intList4.push_back(-2);
intList4.push_back(-7);
intList4.push_back(-8);
cout<<"Baris 38: intList4: ";
copy(intList4.begin(),intList4.end(),screen);
cout<<endl;
intList3.splice(intList3.begin(),intList4);
cout<<"Baris 42: Sesudah elemennya dihapus "
<<"intList4 into intList3,"<<endl
<<" intList3: ";
copy(intList3.begin(),intList3.end(),screen);
cout<<endl;
intList3.sort();
cout<<"Baris 46: Sesudah dipilih, intList3: ";
copy(intList3.begin(),intList3.end(),screen);
cout<<endl;
intList2.merge(intList3);
cout<<"Baris 50: Sesudah di merging intList2 dan intList3, "
<<"intList2: "<<endl<<" ";
copy(intList2.begin(),intList2.end(),screen);
cout<<endl;
intList2.unique();
cout<<"Baris 54: Sesudah dihapus konsekutifnya "
<<"duplicates, intList2: "<<endl
<<" ";
copy(intList2.begin(),intList2.end(),screen);
cout<<endl;
getch();
return 0;
}
C++ itu udah lumayan rumit ngga banyak kepake di dunia kerja gan...
ReplyDelete