Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 8

data structure past paper 2019

(a)

Code for Bubble sort

#include<iostream>

using namespace std;

void bubble_sort(int arr[],int size)

int temp;

for(int i=0;i<size;i++)

for(int j=0;j<(size-1);j++)

if(arr[j]>arr[j+1])

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

cout<<"sorted array:"<<endl;

for(int i=0;i<size;i++)

cout<<arr[i]<<" ";
}

int main()

int b;

cout<<"enter the size of the array: ";

cin>>b;

int a[b];

for(int i=0;i<b;i++)

cout<<"enter a number: ";

cin>>a[i];

bubble_sort(a,b);

video link

https://www.youtube.com/watch?v=Yn5GgBKzWYY

(c)

Remove from head Code

void del_at_head()

if( head != NULL )

node *temp = head;


head = head->next;

delete[] temp;

(d)

output is 5 for the given code

LONG ANSWERS

(b)

BST for the given data


video link

BST: https://youtu.be/ScdwdSCnXDU

MIn heap: https://youtu.be/KzXpfxRzVQM

(c)

CODE for detecting palindrome

#include <iostream>

#include <string>

using namespace std;

void is_palindrom(string word)

int l=word.length();

string w;

int j=l-1;

for(int i=0;i<l;i++)

w[i]=word[j];

j--;

cout<<"the reverse of the word is ";

for(int k=0;k<l;k++)

cout<<w[k];

cout<<endl;

int n;

for(int i=0;i<l;i++)

if (word[i] == w[i])
{

n=1;

else

n=0;

if (n==1)

cout<<"a word is a palindrome "<<endl;

else

cout<<"NO the word is not a palindrome"<<endl;

void is_palindrom(int arr[],int size)

int w[size];

int j=size-1;

for(int i=0;i<size;i++)

w[i]=arr[j];

j--;

cout<<"the reverse of the word is ";

for(int k=0;k<size;k++)
{

cout<<w[k];

cout<<endl;

int n;

for(int i=0;i<size;i++)

if (arr[i] == w[i])

n=1;

else

n=0;

if (n==1)

cout<<"a word is a palindrome "<<endl;

else

cout<<"NO the word is not a palindrome"<<endl;

int main ()

int array[]={1,2,2,1};

is_palindrom(array,4);
is_palindrom("noon");

You might also like