Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C Create a simple set of functions for storing video A linked list of videos

ID: 3795019 • Letter: I

Question

In C

Create a simple set of functions for storing video

A linked list of videos where each video object contains an image object

Each image is contained in a structure, which contains a 2D array

Implement the following header file function declarations

Header File:

Example using API:

struct image* createWhiteImg (unsigned int width, unsigned int height); void setPixel (struct image *img, unsigned int x, unsigned int y, unsigned char grayscale); unsigned char getPixel (struct image img, unsigned int x, unsigned int y) struct video* createEmptyFrameList); struct video* insertFrameUpFront (struct video *video, struct image *img); struct image* getNthFrame (struct video video, int frameNo); struct video* deleteNthFrame (struct video *video, int frameNo);

Explanation / Answer

class LList implements List { private Link head; // Pointer to list header private Link tail; // Pointer to last element private Link curr; // Access to current element private int listSize; // Size of list // Constructors LList(int size) { this(); } // Constructor -- Ignore size LList() { clear(); } // Remove all elements public void clear() { curr = tail = new Link(null); // Create trailer head = new Link(tail); // Create header listSize = 0; } // Insert "it" at current position public boolean insert(E it) { curr.setNext(new Link(curr.element(), curr.next())); curr.setElement(it); if (tail == curr) tail = curr.next(); // New tail listSize++; return true; } // Append "it" to list public boolean append(E it) { tail.setNext(new Link(null)); tail.setElement(it); tail = tail.next(); listSize++; return true; } // Remove and return current element public E remove () { if (curr == tail) return null; // Nothing to remove E it = curr.element(); // Remember value curr.setElement(curr.next().element()); // Pull forward the next element if (curr.next() == tail) tail = curr; // Removed last, move tail curr.setNext(curr.next().next()); // Point around unneeded link listSize--; // Decrement element count return it; // Return value } public void moveToStart() { curr = head.next(); } // Set curr at list start public void moveToEnd() { curr = tail; } // Set curr at list end // Move curr one step left; no change if now at front public void prev() { if (head.next() == curr) return; // No previous element Link temp = head; // March down list until we find the previous element while (temp.next() != curr) temp = temp.next(); curr = temp; } // Move curr one step right; no change if now at end public void next() { if (curr != tail) curr = curr.next(); } public int length() { return listSize; } // Return list length // Return the position of the current element public int currPos() { Link temp = head.next(); int i; for (i=0; curr != temp; i++) temp = temp.next(); return i; } // Move down list to "pos" position public boolean moveToPos(int pos) { if ((pos < 0) || (pos > listSize)) return false; curr = head.next(); for(int i=0; i