DIR Return Create A Forum - Home
---------------------------------------------------------
Learners Tech
HTML https://learnerstech.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Question Board
*****************************************************
#Post#: 30--------------------------------------------------
Question 6 (Placement question)
DIR By: MohanKestrel
Date: July 19, 2017, 11:29 am
---------------------------------------------------------
Given a sorted linked list, delete all duplicates such that each
element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
try it out.....
#Post#: 31--------------------------------------------------
Re: Question 6 (Placement question)
DIR By: user
Date: July 20, 2017, 12:10 pm
---------------------------------------------------------
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20], i, j, k, n;
printf("\nEnter the input size : ");
scanf("%d",&n);
printf("\nEnter %d values : ", n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("\n input values is : ");
for(i=0;i< n;i++)
{
printf(" %d",a[i]);
}
printf("\n without duplicate element : ");
for(i=0; i < n; i++)
{
for(j=i+1; j < n; )
{
if(a[j] == a[i])
{
for(k=j; k < n;k++)
{
a[k] = a[k+1];
}
n--;
}
else {
j++;
}
}
}
for(i=0; i < n; i++)
{
printf("%d ", a[i]);
}
getch();
}
#Post#: 32--------------------------------------------------
Re: Question 6 (Placement question)
DIR By: MohanKestrel
Date: July 24, 2017, 4:28 am
---------------------------------------------------------
Kudos..Superb... Man..
The answer is correct for. Array.
But we have given linked list .
Try it in linked list...
*****************************************************
Page 1 of 1