Sap Labs Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

struct node* reverse(struct node* ptr)
{
struct node* p1,p2,p3;
p1=null;
p2=ptr;//start of linked list;
p3=p2->next;
while(p3!=null)
{
p2->next=p1;
p1=p2;
p2=p3;
p3=p3->next;
}
head=p2;
return(head);
}

- hemant October 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node* reverse(node* head) {
	node* cnode = head;

	while (cnode) {
		if (! cnode->next) {
			break;
		}

		node* tmp = cnode->next->next;
		cnode->next->next = head;
		head = cnode->next;
		cnode->next = tmp;
	}

	return head;
}

- hennes April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct node
{
int data;
struct node *next;
}*head;

void insert_data(int value)
{
struct node *var,*temp;
temp=head;
var=(struct node *)malloc(sizeof(struct node));
var->data=value;

if(head==NULL)
{
head=var;
head->next=NULL;
}
else
{
while(temp->next!=NULL)
{
temp=temp->next;
}
var->next=NULL;
temp->next=var;
}
}

void reverse_list()
{
struct node *temp,*temp1,*var;
temp=head;
var=NULL;
while(temp!=NULL)
{
temp1=var;
var=temp;
temp=temp->next;
var->next=temp1;
}
head=var;
}

void display()
{
struct node *var;
var=head;
printf("\nlist of elments are \n");
while(var!=NULL)
{
printf("-> %d ",var->data);
var=var->next;
}
}

int main()
{
int i,value;
char ch='y';
head=NULL;

printf(" 1.) Insert node");
printf("\n 2.) display the list");
printf("\n 3.) reverse the nodes");
printf("\n 4.) exit");
while(ch=='y')
{
printf("\nChoose to do operation :");
scanf("%d",&i);
switch(i)
{
case 1 :
{
printf("\nEnter the data to be inserted in node ");
scanf("%d",&value);
insert_data(value);
display();
break;
}
case 2 :
{
display();
break;
}
case 3 :
{
reverse_list();
display();
break;
}
case 4 :
{
exit(0);
break;
}
}
}
getch();
}

- Anonymous February 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct node

{
   int data;
   struct node *next;
}*head;

void insert_data(int value)
{
    struct node *var,*temp; 
    temp=head;
    var=(struct node *)malloc(sizeof(struct node));
    var->data=value;

    if(head==NULL)
    {
        head=var;
        head->next=NULL;
    }
    else
    {
         while(temp->next!=NULL)
         {
              temp=temp->next;
         }
         var->next=NULL;
         temp->next=var;
    }
}

void reverse_list()
{
    struct node *temp,*temp1,*var;
    temp=head;
    var=NULL;
    while(temp!=NULL)
    {
         temp1=var;
         var=temp;
         temp=temp->next;
         var->next=temp1;
    }
    head=var;
}

void display()
{
    struct node *var;
    var=head;
    printf("\nlist of elments are \n");
    while(var!=NULL)
    {
         printf("-> %d ",var->data);
         var=var->next;
    }
}

int main()
{
    int i,value;
    char ch='y';
    head=NULL;

    printf(" 1.)  Insert node");
    printf("\n 2.)  display the list");
    printf("\n 3.)  reverse the nodes");
    printf("\n 4.)  exit");
    while(ch=='y')
    {
         printf("\nChoose to do operation :");
         scanf("%d",&i);
         switch(i)
         {
             case 1 :
             {
             printf("\nEnter the data to be inserted in node ");
             scanf("%d",&value);
             insert_data(value);
             display();
             break;
             }
             case 2 :
             {
             display();
             break;
             }
             case 3 :
             {
             reverse_list();
             display();
             break;
             }
             case 4 :
             {
             exit(0);
             break;
             }
        }
   }
getch();

}

- Anonymous February 20, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More