thanks,
i tried to edit but whenever i post, it removes editing. anyway i attached a text file with code and explanation. hope that should work.
please let me know if you still have question.
thanks
hello everybody,
I am trying to implement working sets using STL vector... my code prints pages according to window size. I tried to print pages without repetition..but I could not do that....can anybody help me with correct loop which checks whether the page is already in the vector or not and then prints pages without repetition.
my code is :
and my output is:Code:#include<stdio.h> #include<unistd.h> #include<vector> #include<iostream> using namespace std; class workset { public: void workingset(int,int,int*); }; // n is the array size, w is the window size and pages is the list of pages. void workset::workingset(int n, int w, int pages[]) { int j,count=0,k; int count2; int i; vector <int> v; printf("\nthe list is= ");//first prints the list for(k=0;k<n;k++) printf("%d,", pages[k]); printf("\n"); printf("Time \t Size \t Set\n"); for (int time=w-1;time<n;time++) { count2=count; for(i=0;i<w;i++) { v.push_back(pages[count2]); count2++; } printf("%d \t %d \t ",time,v.size()); for (j=0;j<v.size();j++) printf("%d ",v[j]); printf("\n"); v.erase(v.begin(),v.end()); count++; } printf("\n"); }; int main() { workset w1,w2; int list1[] = {1,2,3,3,2,3,2,1,2,1,2,1,3,1,3,1,2,3,1}; int list2[] = {1,2,3,3,4,4,5,3,3,2,1,2,1,2,3,4,5,3,2,4,2,4,2,2}; w1.workingset(sizeof(list1)/sizeof(int),3,list1); w2.workingset(sizeof(list2)/sizeof(int),4,list2); return 0; };
the list is= 1,2,3,3,2,3,2,1,2,1,2,1,3,1,3,1,2,3,1,
Time Size Set
2 3 1 2 3
3 3 2 3 3
4 3 3 3 2
5 3 3 2 3
6 3 2 3 2
7 3 3 2 1
8 3 2 1 2
9 3 1 2 1
10 3 2 1 2
11 3 1 2 1
12 3 2 1 3
13 3 1 3 1
14 3 3 1 3
15 3 1 3 1
16 3 3 1 2
17 3 1 2 3
18 3 2 3 1
the list is= 1,2,3,3,4,4,5,3,3,2,1,2,1,2,3,4,5,3,2,4,2,4,2,2,
Time Size Set
3 4 1 2 3 3
4 4 2 3 3 4
5 4 3 3 4 4
6 4 3 4 4 5
7 4 4 4 5 3
8 4 4 5 3 3
9 4 5 3 3 2
10 4 3 3 2 1
11 4 3 2 1 2
12 4 2 1 2 1
13 4 1 2 1 2
14 4 2 1 2 3
15 4 1 2 3 4
16 4 2 3 4 5
17 4 3 4 5 3
18 4 4 5 3 2
19 4 5 3 2 4
20 4 3 2 4 2
21 4 2 4 2 4
22 4 4 2 4 2
23 4 2 4 2 2
but for example it should print
the list is= 1,2,3,3,2,3,2,1,2,1,2,1,3,1,3,1,2,3,1,
Time Size Set
2 3 1 2 3
3 2 2 3
4 2 3 2
5 3 3 2
6 3 2 3
and so on......
I would appreciate any help...