public void removeByStart(int i) { process tmp = findByStart(i); process tmp2 = tmp.get_next().get_next(); tmp.set_next(tmp2); }
public int[] allEle(int j) { process tmp = head; int s = size(); int[] arr = new int[s]; if (j == 0) { for (int i = 0; i < s; i++) { arr[i] = tmp.get_start(); tmp = tmp.get_next(); } } else if (j == 1) { for (int i = 0; i < s; i++) { arr[i] = tmp.get_end(); tmp = tmp.get_next(); } } else if (j == 2) { for (int i = 0; i < s; i++) { arr[i] = tmp.get_size(); tmp = tmp.get_next(); } } return(arr); }
public void removeByName(string name) { process tmp = head; if (size() == 1) { head = null; return; } else if (tmp.get_processName() == name) { head = tmp.get_next(); return; } else { tmp = tmp.get_next(); while (tmp.get_processName() != name && tmp.get_next() != null) { tmp = tmp.get_next(); } process tmp2 = tmp.get_next(); tmp.set_next(tmp2.get_next()); } }
private void button2_Click(object sender, EventArgs e) { process toBlackWhite = new process(); Bitmap image = new Bitmap(pictureBox1.Image); toBlackWhite.blackWhite(image); pictureBox2.Image = image; }
public process(string str, int startAt, int size, int hole) { mNext = null; mProcessName = str; mStart = startAt; mSize = size; mEnd = startAt + size - 1; mHoleNum = hole; }
public process findByEnd(int i) { process tmp = head; while (tmp.get_end() != i) { tmp = tmp.get_next(); } return(tmp); }
public process findByName(string i) { process tmp = head; while (tmp.get_processName() != i) { tmp = tmp.get_next(); } return(tmp); }
public process findBySize(int i) { process tmp = head; while (tmp.get_size() != i) { tmp = tmp.get_next(); } return(tmp); }
public process last() { if (isEmpty()) { return(null); } process tmp = head; while (tmp.get_next() != null) { tmp = tmp.get_next(); } return(tmp); }
public void Add(string str, int start, int size, int holeNum) { process nw = new process(str, start, size, holeNum); if (isEmpty()) { head = nw; } else { process tmp = last(); tmp.set_next(nw); } }
public int size() { if (isEmpty()) { return(0); } int i = 1; process tmp = head.get_next(); while (tmp != null) { i++; tmp = tmp.get_next(); } return(i); }
public void swap(process tmp, process tmp2) { int tmpHN = tmp2.get_holeNum(); int tmpStart = tmp2.get_start(); int tmpSize = tmp2.get_size(); int tmpEnd = tmp2.get_end(); tmp2.set_start(tmp.get_start()); tmp2.set_size(tmp.get_size()); tmp2.set_holeNum(tmp.get_holeNum()); tmp2.set_end(tmp.get_end()); tmp.set_start(tmpStart); tmp.set_size(tmpSize); tmp.set_holeNum(tmpHN); tmp.set_end(tmpEnd); }
public int processlistSize() { if (isEmpty()) { return(0); } process tmp = head; int i = 0; while (tmp != null) { i = i + tmp.get_size(); tmp = tmp.get_next(); } return(i); }
public void printPro() { mPro.sort(0); process pro = mPro.get_hProcess(); int size = mPro.size(); for (int i = 0; i < size; i++) { string proName = pro.get_processName(); int start = pro.get_start(); int end = pro.get_end(); listBox2.Items.Add(proName + " from " + start + " to " + end); pro = pro.get_next(); } printHoles(); }
public void remove(process p) { process tmp = head; if (size() == 1) { head = null; return; } else if (tmp == p) { head = tmp.get_next(); return; } else { while (tmp.get_next() != p && tmp.get_next() != null) { tmp = tmp.get_next(); } process tmp2 = tmp.get_next(); tmp.set_next(tmp2.get_next()); } }
private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e) { int ind = listBox2.IndexFromPoint(e.X, e.Y); string tmp = listBox2.Items[ind].ToString(); int indexOfSpace = tmp.IndexOf(" ", 0); string str = tmp.Substring(0, indexOfSpace); listBox1.Items.Clear(); listBox2.Items.Clear(); process p = mPro.findByName(str); int holeNum = p.get_holeNum(); hole h = mMem.findByHoleNum(holeNum); int proEnd = p.get_end(); int proStart = p.get_start(); int proSize = p.get_size(); mMem.sort(0); int[] startArr = mMem.allEle(0); int[] endArr = mMem.allEle(1); int limit = mMem.size(); bool ok = true; for (int i = 0; i < limit; i++) { if (proEnd <= endArr[i] && proStart >= startArr[i]) { mErrorMsg = "already hole"; MessageBox.Show(mErrorMsg); ok = false; break; } else if ((i < limit - 1) && (proEnd + 1 == startArr[i + 1] && proStart - 1 == endArr[i])) { hole tmpH = mMem.findByStart(startArr[i]); hole tmpH2 = mMem.findByStart(startArr[i + 1]); tmpH.set_end(tmpH2.get_end()); tmpH.set_size(proSize + tmpH.get_size() + tmpH2.get_size()); mMem.removeByStart(startArr[i + 1]); ok = false; break; } else if (proEnd + 1 == startArr[i] || (proEnd >= startArr[i] && proEnd <= endArr[i])) { hole tmpH = mMem.findByStart(startArr[i]); tmpH.set_start(proStart); tmpH.set_size(endArr[i] - proStart + 1); ok = false; break; } else if (proStart - 1 == endArr[i] || (proStart <= endArr[i] && proStart >= startArr[i])) { hole tmpH = mMem.findByEnd(endArr[i]); tmpH.set_end(proEnd); tmpH.set_size(proEnd - startArr[i] + 1); ok = false; break; } } if (ok) { mMem.Add(mHoleNum, proStart, proSize); enProcess(); mHoleNum++; } mPro.remove(p); if (mPro.size() == 0) { enHole(); } printPro(); }
public void set_next(process p) { mNext = p; }
public ProcessLinkedList() { head = null; }
public void sort(int sel) { process tmp = head; int n = size(); int x, y; if (sel == 0) { for (x = 0; x < n; x++) { process tmp2 = tmp.get_next(); for (y = 0; y < n - x - 1; y++) { int c = tmp.get_start(); int nn = tmp2.get_start(); if (c > nn) { swap(tmp, tmp2); } tmp2 = tmp2.get_next(); } tmp = tmp.get_next(); } } else if (sel == 1) { for (x = 0; x < n; x++) { process tmp2 = tmp.get_next(); for (y = 0; y < n - x - 1; y++) { int c = tmp.get_end(); int nn = tmp2.get_end(); if (c > nn) { swap(tmp, tmp2); } tmp2 = tmp2.get_next(); } tmp = tmp.get_next(); } } else if (sel == 2) { for (x = 0; x < n; x++) { process tmp2 = tmp.get_next(); for (y = 0; y < n - x - 1; y++) { int c = tmp.get_size(); int nn = tmp2.get_size(); if (c > nn) { swap(tmp, tmp2); } tmp2 = tmp2.get_next(); } tmp = tmp.get_next(); } } }