1.find the second maximum in an array?
2.how do you create hash table in c?
3.what is hash collision
Answers were Sorted based on User's Feedback
Answer / sachin
1.#include<stdio.h>
int main()
{
int a[10]={222,111,4,5,6,8,1,77,0,4};
int i=0,max=0,sec_max=0;
for(i=0;i<10;i++)
{
if(a[i]>max)
{
sec_max=max;
max=a[i];
}
else if(a[i]>sec_max)
{
sec_max=a[i];
}
}
printf("Max= %d Second Max=%d",max,sec_max);
}
Is This Answer Correct ? | 23 Yes | 2 No |
Answer / steven le
1. Selection sort with second pass
2. Basically we create a two dimension array (key, value)
and then we define a hash function to determine position of
elements when we insert/delete.
3. When two elements insert to the same spot in a hash
table, we have a hash collision. H(x1) = H(x2) = y
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / abdur rab
#include <stdio.h>
int main ( int argc, char* argv[] )
{
int* array_int, nTotalCount = 10, sbig, big, i;
printf ( "\n/********************** Second Biggest
Number ********************/" );
array_int = ( int* ) malloc ( nTotalCount * sizeof
( int ) );
for ( i = 0; i < nTotalCount; i++ )
array_int [i] = rand() % 100;
printf( "\nThe Numbers in given order" );
for ( i = 0; i < nTotalCount; i++ )
printf ( "\t%d", array_int [i] );
for ( i = 0; i < nTotalCount; i++ )
{
switch ( i )
{
case 0:
sbig = big = array_int [i];
break;
default:
if ( big < array_int [i] ) {
sbig = big;
big = array_int [i];
} else {
if ( sbig <
array_int [i] ) sbig = array_int [i] ;
}
break;
}
}
printf ( "\n sbig :%d big :%d", sbig, big );
free ( array_int );
}
For hashtable please refer the following link
http://www.geocities.com/abdur_rab7/Open_Hash/openhash.html
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / dishant srivastava
void max_two(unsigned char A[], unsigned char Size,
unsigned char *first, unsigned char *second)
{
unsigned char i;
*first = A[0];
for(i = 1; i < Size; i++)
{
if(*first <= A[i])
{
*second = *first;
*first = A[i];
}
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / shanthi
#include<stdio.h>
int main()
{
int array[5]={2,3,4,6,5};
int max=a[0];
int sec=a[1];
for(i=0;i<5;i++)
{
if(a[i]>max)
max=a[i];
}
for(i=0;i<5;i++)
{
if((a[i]>sec )&&(a[i]<max))
{
sec=a[i];
}
}
printf("%d %d",max,sec);
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / rao
#include<stdio.h>
int main()
{
int arr[] = {2,3,20,7,8,1};
int max, sec;
int i;
max=0;
sec=0;
for ( i=0; i< 6; i++)
{
if(arr[i] > max)
max = arr[i];
}
for ( i=0; i< 6; i++)
{
if ( (arr[i] > sec) && (arr[i] < max))
sec = arr[i];
}
printf(" max=%d\n sec=%d\n", max, sec);
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / shanthi
2.
hash table is a table with one row with 10 columns say.
now to create hash table
struct phonerec
{
char name;
int phoneno;
};
struct node
{
struct phonerec r;
struct node *pnext;
};
struct node *hash[10];
int hashfun(int phoneno)
{
return phone%10;
}
int add(struct phonerec *pr);
{
struct node *pn;
pn = malloc(sizeof(*pn));
pn->r=*pr;
int hix=hashfun(pr->phoneno);
pn->pnext=hasharray[hix];
hasharray[hix]=pn;
return SUCCESS;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / jaypal rajput
//find second maximum number in given array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5];
int max=0,secmax=0,i;
cout<<"Enter element";
for(i=0;i<=4;i++)
{
cin>>a[i];
}
for(i=0;i<=4;i++)
{
if(a[i]>max)
{
secmax=max;
max=a[i];
}
if(a[i]>secmax&&a[i]<max)
{
secmax=a[i];
}
}
cout<<"The max element is="<<max;
cout<<"the sec max is="<<secmax;
getch();
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / vignesh1988i
#include<stdio.h>
#include<conio.h>
void soft(int *,int *);
void main()
{
int a[30],n;
printf("enter the number of elements going to enter :");
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",a[i]);
soft(a);
printf("the second maximum in the given array is :");
getch();
}
void soft(int *a,int *n);
{
int temp;
for(int i=0;i<(*n);i++)
{
for(j=0;j<(*n);j++)
{
if(a[j+1]<a[j])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
printf("%d",a[n-1]);
}
sorry i dont know the concept of hash table!!!!!!!!!!!!!!!
Is This Answer Correct ? | 1 Yes | 18 No |
What is f'n in math?
When c language was developed?
how can i include my own .h file EX:- alex.h like #include<alex.h>, rather than #include"alex.h"
let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
What are the two forms of #include directive?
? ???Mirror Mirror on the wall????????
whats the use of header file in c?
Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes. If an intrusion attempt is detected beep the internal speaker to alert the administrator. A high number of aborted connects to MySQL at a point in time may be used as a basis of an intrusion.
2 Answers Drona Solutions, Infosys, Vodafone, Webyog,
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
What is the difference between ‘g’ and “g” in C?
Explain bit masking in c?
What is the memory allocated by the following definition ? int (*x)[10];