[go: up one dir, main page]

0% found this document useful (0 votes)
125 views6 pages

Program 1

A program to implement various sorting algorithms and data structures: 1) Quicksort to sort an array using divide and conquer. 2) Insertion sort to iteratively build a sorted list from an unsorted array. 3) A class to calculate the Möbius function of a natural number. 4) Implement a queue and double-ended queue simultaneously using a linked list. 5) A Quote class that stores words in a quote using an internal linked list class Card.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views6 pages

Program 1

A program to implement various sorting algorithms and data structures: 1) Quicksort to sort an array using divide and conquer. 2) Insertion sort to iteratively build a sorted list from an unsorted array. 3) A class to calculate the Möbius function of a natural number. 4) Implement a queue and double-ended queue simultaneously using a linked list. 5) A Quote class that stores words in a quote using an internal linked list class Card.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM-1

A class teacher has created a text file "RV.txt" to store the details of all the
students. Write a menu driven program to perform the different tasks as
specified:
(i) To display the details of each and every student as specified in the file
"RV.txt"
(ii) To display the record getting the highest total.

Use the concept of file operations to deal with the above problem.
PROGRAM 2

Quick Sort is a Divide and Conquer algorithm which can be implemented to


sort all the elements of an array. It picks an element as pivot and partitions the
given array around the picked pivot.

Write a program to implement Sorting of an array using the technique of


Quick Sort.
PROGRAM 3

Insertion sort is a simple sorting algorithm that builds the final sorted
array (or list) one item at a time. Insertion sort iterates, consuming one input
element each repetition, and growing a sorted output list. At each iteration,
insertion sort removes one element from the input data, finds the location it
belongs within the sorted list, and inserts it there. It repeats until no input
elements remain.

Write a program to implement the concept of sorting of an array using


Insertion Sort technique.
PROGRAM 4

The MOBIUS function M(N) for a natural number N is defined as follows:

M(N) = 1 if N = 1 [Condition 1]

M(N) = 0 if any prime factor of N is contained in N more than


once [Condition 2]

M(N) = (-1)^p if N is a product of ‘p’ distinct prime factors


[Condition 3]

Design a class MobiusFn to define Mobius function for a natural number n.


PROGRAM 5

Write a program to implement concepts of a Queue and a D-queue (Double


ended queue) simultaneously.

Queue is an abstract data structure which is open at both its ends. One end is
always used to insert data and the other is used to
remove data. Queue follows First-In-First-Out methodology, i.e.,
the data item stored first will be accessed first.
PROGRAM 6

Write a program to implement the following class that adds words to a Quote
using a linked list.

Class Name: Quote

Member methods:

Quote(String w)- To create a quote whose first word is w


void addWord(String w)- Add String w to the end of the quote.
int count()- To return the number of words in the quote
String getword(int i)- Return the word at the “i”th index
void insertWord(int i, String w)- add w after the “i”th word
String toString()- return the entire quote as a String

To do so, define another class Card(defined inside Quote) that holds one word
of the quote and a link to the next word. Use this code snippet:

private class Card


{
private String word;
private Card next;
public Card(String word)
{
this.word=word;
this.next=null;
}
}

You might also like