104 cribsheet.docx - int dLnJ ”distances lrnm the start...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int dLnJ; ”distances lrnm the start nods u int pEnJ: l/pmedeussan int chi] [u]: [lodge casts void Dijkstn (int u) [ Prierityflusuaflut) pqO: sin] - n,- pq...n<u, diul); uhile‘lquafi'flptyu) { int v - mam“); quemwaE): //nodes are named 0 through n-1 int dbl]; //stores distances from 11 int pin]; ”stores paths void BFS(int u) {//u is the start node enqueue node u d[u] = 0; int binarySsath (int n, int» 1:. int lsn) while the queue is not empty { I/Hml should we implement this? class Him-leap { public: private: int ta; // stores the priorities int map; // stores the locations of each node }; { . _ . dequeue the next node v for n11 nod“ outgoing ads" (VJ) from v 1: void Mini-leap: :UpdatePriority(int node, int priority) { int 1:: - D. h: - len, laid; for all outgoing edges (v,w) from v { if (. hum-t 1mm visit,“ || ah] . gmm < am) { int location = map[node]; "Ml-9‘10 “ 111) 'I if we haven’t yet visited w { div] v div] i civllw]: if (aflocationJ < priority) { mid - (hi+1:w)l2; d[w] = d[v]+1; PM ' “1 a[location] = priority; if (bfmidl‘fll) return mid: p5,] = v; //tells us which node led to u 1! (this in H’s first visit) I trickleDown(1ocation); else no: < blnidl) ire-mi"): hi _ nid-i- enqueue node v 1 } else { 91“ 1° . mm: ) .1" mtnpmm. FM); a[location] = priority; 3 I } } } bubbleUp(1ocation); return -1.; } ;. l l } 3 } int first; . try { . ofstream myFile; n t n n+1 string second‘ . _ 0 21:1 1, : 42—2 : 601?). ’1 cout << LL—>get(15) << endl; char third; ' myFlle-Open(”gameS-txt” ), cout << ”Printedcsuccessfullyl” << endl; catch (logic,error &e) { string fourth; . 221:0 60"") : 6(np+l). Thi } stringstream ss; ifstream myFile << " 1:nMinecraft” << endl; myFile. close 0; myFile2; myFileZ . open(”gamesi txt” ); getline (myFile2 , line); cout << ”Aslogiccerrorsoccuredl” << endl;SS <<”'1=uMine°“ft"i strin line‘ . 2? Ci = g = 0(c”) °°“‘ << “Wham? :3 :: :éiilé- g 7 i=0 c—l ' } catch (exception lice) { as >> third-Y cout << ”Generalcexception” << end]; as >> fourth; cout << line: H 1 _ ' 21:1 E — T H; int InterpolationSsnrch(T x, int 1, int 1) { if (r <1) return —1; 6(logn). This is } class Shape { cout << first << endl myFile2.close 0; If (B[ll' iii—“HHS return r‘ public: LinkedListzzIterator LinkedListzzbeginO const { return—d. ' Shape(); LinkedList: :Iterator 11i(this, head); } ’ virtual ”ShapeO; return lli; int 111: (x_a[1])/(5[,]_a[1]).(,_1)+1; Virtual VOld draw() : 0; } if (s[m] = it) return 11.; LinkedList::lterator LinkedListzzendO const { lf (a[m] < x) return InterpolationSenzch(x, m+l, :);}7 . return InterpulstionSesruh(x, i, m—i); class Triangle public Shape { . return 11s; : public Shape { >}; LinkedList: :Iterator 118(this, NULL); '1' Prinzityflueus: ipsako cann { return ate]: } void PriorityDusus::add(cnnat Tit data) { aEsize] - data; hubbleUp (size) : size»; )- vold Privrityflueueububblsilpfint pas) { 1: (1105 > 0 Mt |[p03] > s[(poe-1)l2]) { e.swsp(pus. (pus-1N2); bubbleUp< (pun-1V2): } )- void Priority-Queue: :nanwvso { a.sHep(0,size-1)'. aiza--; tricklaDwnw)‘, } void Priorityuueue: :tricklanowutint pas) { int child - 2upost-l; if (child < sizn) { if (childu < size n eternal < aEch11d+1D child++; if menu] > e[pos]) { s.swsp(uhild. Pas); trickleDov-Mchild) ,- } } } for (int i : 0; i < size; i++) newArray.data[i] : data[i]*multiplier; Armyuuperatoi: {const IntAi-ray &otherArray) { } class Square } void MergsSnrt(T El]. int 1, int r) { if (kr) { int m: floor((l+r)/2); MsrgsSDrt[n.l ,m); MsrgeSurt(n.m-+l.l ); void QuickSoi-t (T all, in: 1, int 1') { Merse(a~l.r.m): if (1 < r) { ) “1.2m: partition(s,l.r); vnid Merge (T 3|], int 1. int 1'. int In) ( Insertion Son. QuickSort (21,1 ,m—l); int i:]Y j : n+1. kla; for (int i = 1; i < n; i++) ( Q“‘°k3°“(asm+1fili while (i (:m H j<: r) i intjsi; } if(i<=mx'&(i>fHalil<nllllll while (j>0&i!za.[j]<n{j—1]) { } femplkl=n[i]: Lamp“ ,5 —1); int partition [T a” , int 1, int 1') { i++; k++: Ii“; int i=1; )1 { T p : ah]; e 5° . - - - . t k 2 ; } £01: (mt‘J = 1: J < r; J++){ :12“ ELL]; Selectionfiort If (BlJl $713) { 1 . . _. _, a-swapllyi); ] for (int i : O, i < n—lV i++) { H—H for (kzfl; k< r+l—l; k++) n[k+1] : tsmp[k]; Int smallest = ; } l for (in! j = i+l: j < n; j++){ } il' (a[J] < sleinsllestlj smallest : J; s.swsp(i ,t); There: eerelszionlorMergeSni-tis: s,swep(i,smsllest): return ii T(n)=2T(%)+9(n) } } T(1)=e(1). class IntArrsy { public: , . _ hoal operator:(const IntArrsy& whammy) { IntArray IntArrayzzoperator>k (int multiplier) { if (this—>size !: otherArrsyJize) return false: IntArray newArray; for(int i=0; i<size; i++) newArray.size : size; if (thi5*>dtlta[l] I= otherArrsy.dsta.[i]) return false; } ”tum “I“; return newArray; has: operator [1 (Int index) { } return data[index]; lntArray& Int l . , . thisi>size — Dthei’Array.size; Imfgfllftofefgfltusige; i++) data{i]++; this—>dats = new intlthis—>size]; return *this; for (int i.= 0; i < this—>size; i++) this—>dsts[i] } return ttlus; private: } int size; int *deta; l; int *q: llpositions of the queens int n; I'lsize of the grid int Mt: ”threatened squares l L'Dk dL' 1‘: c ass 1 6 15 { void search (int row) { Puziiz; Iterator { if (Iow=n) printSalutiDnO; ”Show the layout public: else { for(q[rov]=0; qkou] < 11: qh’ofl“) if (t [row] [qfroifll = 0) { change‘l'hraats(rou, qfiou], l)://queen placed herel searclfirowfi.) : :hsnge'l'hrsats(row, q[rnu] , -1) :f/qiiesn removed from } friend class LinkedList; int& operator* 0 const; LinkedList: :Iterator operator++0 ; bool operator=(const LinkedList: :Iterstor lather) const; bool operator!=(const LinkedLiet: :Iterator hathar) const; private: Iterator(canst LinkedList *w, Item *c); Itemr curr; } } void changeThrescsCint row, int column, int change) { for (intj = row-t1; j < n: jH-l ‘l t[j] [colum] +- change; if (column+(j-rou) < n) tL‘i] [column+(j-row)] += change; if (column-(j-rou) >= 0) tlj] [colimn-(j-rawll += change; }; void insert(int x); LinkedList: :Iterator beginO const; LinkedList: :Iterator endO const; private: Item)!I head; }: } } void printSolutionO { 1mm 1 - 0; 1 < :1; i++) { for(int j = 0; j < n; j++) { if (j = q[i]) caut << “n"; else cont << "-"3 } cout << endl; ) } int maintvoid) { cin >> 11; q = new intfii]; t - new intr Ell: for (int i - 0; i < :1; i++) { tEi] = new intln]: here! for (int j = 0: j < 13.; j“) t[i][j] = 0: J search (0) : delete E] q: delete E] t; [lone new, one delete! return 0; void UpdatePriority(int node, int priority); otherArray . deta.[ i I; ...
View Full Document

{[ snackBarMessage ]}

0/0 PREVIEWS LEFT
Sign up to access 24/7 study resources for your classes

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern