pgm to find middle element of linklist(in efficent manner)
Answers were Sorted based on User's Feedback
Answer / abdur rab
struct node {
int data;
struct node* next;
};
int mid_element ( struct node* _node )
{
struct node* cur_ptr;
struct node* cur_next_ptr;
if ( NULL == _node ) return ( -1 );
else {
cur_ptr = _node;
cur_next_ptr = _node;
while ( ( NULL != cur_ptr -> next )
&& ( NULL != cur_next_ptr -
> next )
&& ( NULL != cur_next_ptr -
> next -> next ) )
{
cur_ptr = cur_ptr -> next;
cur_next_ptr = cur_next_ptr ->
next -> next;
}
}
return ( cur_ptr -> data );
}
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / sharan
NODE display_middle(NODE first)
{
int count = 0;
NODE temp,mid;
for ( temp = mid = first, count=0; temp ; temp = temp ->
link,count++)
{
if ( count % 2 )
{
mid = mid -> link;
}
}
return mid;
}
Is This Answer Correct ? | 6 Yes | 2 No |
Answer / ashwini
struct node
{
int data;
struct node *ptr;
};
struct node mid_element(struct node* head)//since we pass addr
{
int count=0,n_count,i=0;
struct node* temp,*mid;
temp=mid=head;
while(temp -> ptr != NULL)
{
count++;
temp = temp->otr;
}
count++;
if(count % 2)
{
n_count = (count/2)+1;
for(i=0 ; i<n_count ; i++)
mid = mid -> ptr;
}
return mid;
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vishnu
typedef struct LL_tag
{
int data ;
struct LL_tag *next ;
} LL ;
/*Pass a valid singly linked list*/
LL* Mid (LL *head)
{
LL *one, *two ;
one = two = head ;
while (two)
{
two = two->next ;
if (two)
{
two = two->next ;
one = one->next ;
}
else
{
two = NULL ;
}
}
return one ;
}
Is This Answer Correct ? | 2 Yes | 0 No |
find the minimum of three values inputted by the user
What is static identifier?
What does node * mean?
What is the difference between printf and scanf in c?
Explain high-order and low-order bytes.
main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }
What is omp_num_threads?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration
write a c program to remove all the duplicate characters in a string and replace with single character? ex:-input- AAABBBCCC output- ABC
What is static memory allocation? Explain
whether itis a structured language?