0% found this document useful (0 votes)
11 views2 pages

07_linked_list_stack_queue

The document outlines a lab assignment for CSC10012 focusing on linked lists, stacks, and queues. It provides function prototypes for various operations on linked lists, such as adding, removing, and printing nodes, as well as managing duplicates. Additionally, it describes how to utilize linked lists to implement stack and queue data structures with corresponding operations.

Uploaded by

phuctran180406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

07_linked_list_stack_queue

The document outlines a lab assignment for CSC10012 focusing on linked lists, stacks, and queues. It provides function prototypes for various operations on linked lists, such as adding, removing, and printing nodes, as well as managing duplicates. Additionally, it describes how to utilize linked lists to implement stack and queue data structures with corresponding operations.

Uploaded by

phuctran180406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSC10012

LAB 07 – LINKED LIST & STACK & QUEUE


FIT-HCMUS

Part 1 – Linked List


Given the following singly linked list definition:

struct Node { struct List {


int key; Node* pHead;
Node* pNext; Node* pTail;
}; };

Implement the following function declarations/prototypes:

1. Initialize a Node from a given integer 9. Remove node(s) after the node(s) with the speci-
Node* createNode(int data); fied val value in a linked list
void removeAfter(List &L, int val);
2. Initialize a List from a give Node
List createList(Node* pNode); 10. Insert an integer at a specific position of a liked list
void addPos(List &L, int data, int pos);
3. Insert an integer to the head of a linked list
void addHead(List &L, int data); 11. Remove a node at a specific position of a linked list
void removePos(List &L, int pos);
4. Insert an integer to the tail of a linked list
void addTail(List &L, int data);
12. Insert an integer before the node(s) with the spe-
cific val value in a linked list
5. Remove the first node of a linked list
void addBefore(List &L, int data, int val);
void removeHead(List &L);

6. Remove the last node of a linked list 13. Insert an integer after the node(s) with the specific

void removeTail(List &L); val value in a linked list


void addAfter(List &L, int data, int val);
7. Remove all nodes from a linked list
void removeAll(List &L); 14. Print all elements in a linked list
void printList(List L);
8. Remove node(s) before the node(s) with the speci-
fied val value in a linked list 15. Count the number of elements in a linked list
void removeBefore(List &L, int val); int countElements(List L);

1
16. Create a new linked list by reversing the given keeping the first occurrence of each one
linked list void removeDuplicate(List &L);
List reverseList(List L);
18. Remove all nodes that have a value equal to key
17. Remove all duplicate elements from a linked list, bool removeElement(List &L, int key);

Part 2 – Stack-Queue
Utilize the existing linked list to define the stack and queue data structures. Next, implement functions for the
following operations:

1. Stack 2. Queue
• Initialize a stack from a given key. • Initialize a queue from a given key.

• Push a key into a stack. • Enqueue a key into a queue.

• Pop an element out of a stack, the key’s value will • Dequeue an element out of a queue, the key’s
be returned. value will be returned.

• Count the number of elements in a stack. • Count the number of elements in a queue.

• Check if a stack is empty. • Check if a queue is empty.

You might also like