













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19 : Data Structures and Algorithms Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Dinh Duc Thuan Student ID GCD Class GCD0705 Assessor name Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Grading grid P1 P2 P3 M1 M2 M3 D1 D
Summative Feedback: Resubmission Feedback: Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
I. Create a design specification for data structures explaining the valid operations that can be carried out on the structures.
1. What is Queue?
b) Operation Enqueue:
Dequeue
Queue Code – Input: class Queue { public: int Max; int Q[ 100 ; int front, last; Queue () { front = 0 ; last = 0 ; Max = 100 ; } bool isEmpty () { if ( isEmpty()) cout<<"khong lay duoc nua"; else { int x = Q[front] ; front = (front + 1 ); } return last == front; } void enqueue ( int x () { if (soPhanTu() == Max + 1 ) cout<<"da day"; else Q[last] = x; last = (last + 1 ) % Max; last = (last + 1 ) % Max; Q[last] = x; }
int dequeue () { if (isEmpty()) cout<<""; return - 1 ; int x = Q[front] ; front = (front + 1 ) % Max; return x ; } int peek () { return Q[front] ; } int soPhanTu () { return ((Max - front) + last) % Max; } }; Output : Figure 6 Result of programming
b) Stack implementation the computer
c) Function call
2. Specify Stack data structures including Data type and its operations a) Stack data Structure
d) Real life example
Stack Code - Input: class Stack { //data public : int Max; int Top; int S [ 100 ]; //operation public : Stack () { Max = 100 ; Top = - 1 ; } bool isEmpty () { return (Top == - 1 ); } void push ( int x){ Top++; S[Top] = x; } int pop (){ int x = S[Top]; Top--; return x; } int top (){ return S[Top]; } void convert ( int x){ while (x != 0 ) { int r = x % 2 ; push(r) ; x = x/ 2 ; } while (! isEmpty ()) { Cout<<pop(); } } };