Linked List Class-Handling Data Structures-Quiz, Exercises of Data Structures and Algorithms

This quiz was taken in class of Data Structure course by Shekhar Sharma at B R Ambedkar National Institute of Technology. It includes: Linked, List, Class, Implement, Functions, Remove, Node, Swap, Last, Protected, Public, Items

Typology: Exercises

2011/2012

Uploaded on 07/11/2012

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS2143-2144 Data Structures Spring 2012
Quiz # 7(17 April 2012)
Time 10 Minutes
Max. Marks 10
Name: Reg. No: ___
For the following linked list class, implement the following functions. Assume all other
functions given in the class have already been implemented.
void removeSecond() //remove every second node from the linked list
void swapTwo(node *p, node *q) //swap the nodes p and q in the linked list
void removeSecondLast () //remove the second last node of the linked list
class linked_list
{
protected:
struct node
{
int item;
node *next;
}
node *head; //pointer to the first node of the linked list
node *get_node();
void free_node(node *);
public:
linked_list();
void insert (int x); //insert at the end of the linked list as the last entry
void remove (node *p); //remove the node with pointer p from the linked list
void list_item(); //print all the items of the linked list
void removeSecond(); //remove every second node from the linked list
void swapTwo(node *p, node *q); // swap the nodes p and q in the linked list
void removeSecondLast (); //remove the second last node of the linked list
};
Docsity.com

Partial preview of the text

Download Linked List Class-Handling Data Structures-Quiz and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CS2143-2144 Data Structures Spring 2012

Quiz # 7(17 April 2012)

Time 10 Minutes

Max. Marks 10

Name: Reg. No: ___

For the following linked list class , implement the following functions. Assume all other

functions given in the class have already been implemented.

**void removeSecond() //remove every second node from the linked list void swapTwo(node p, node q) //swap the nodes p and q in the linked list void removeSecondLast () //remove the second last node of the linked list class linked_list { protected: struct node { int item; node *next; } node *head; //pointer to the first node of the linked list node *get_node(); void free_node(node *); public: linked_list(); void insert (int x); //insert at the end of the linked list as the last entry void remove (node *p); //remove the node with pointer p from the linked list void list_item(); //print all the items of the linked list **void removeSecond(); //remove every second node from the linked list void swapTwo(node p, node q); // swap the nodes p and q in the linked list void removeSecondLast (); //remove the second last node of the linked list };

Docsity.com