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 |
Is exit(status) truly equivalent to returning the same status from main?
What is uint8 in c?
main() {int i=5; // line 1 i=(++i)/(i++); // line 2 printf("%d",i); // line 3 } output is 2 but if we replace line 2 and line 3 by printf("%d",i=(++i)/(i++)); then output is 1. Why?
Is anything faster than c?
Write a programme to find even numbers without using any conditional statement?
3 Answers ADD Software, Infosys,
What is a example of a variable?
What is your favorite subject?
1 Answers Ericsson, Invendis, Tech Mahindra,
plssssss help !!....using array.. turbo c.. create a program that will accept number of words to be consored. .a word must not exceed 10 characters long .the text to be entered will be no longer than 200 characters .there will be no 10 words example: enter number of words to be censor: 5 enter words to censor: windows office microsoft bill gates enter text to censor: bill gates founded microsoft and makes office and windows sample output: <consored> <censored> founded <censored> and makes <censored> and <censored>
typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { stptr->i = 99; return stptr->i; } main() { st_temp local; int i; local.c = 'v'; local.i = 9; local.f = 23.65; printf(" %d %c %f",local.i,local.c,local.f); i = getdata(&local); printf("\n %d",i); getch(); } why there there is an error during compiling the above program?
Write a C program to get the desired output. 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 . . . 1 n..............n 1 Note: n is a positive integer entered by the user.
who is first prime minister in india??
Explain how can I make sure that my program is the only one accessing a file?