| | |
Efficient code for extracting unique elements from sorted array.
Efficient code for extracting unique elements from sorted array.
Time Complexity is O(n)
Time Complexity is O(n)
#include<stdio.h> main() { int i,a[20],n,t,j,k; printf("\n Enter the number of elements in sorted list"); scanf("%d",&n); printf("\n enter the sorted numbers with duplicates"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) t+=a[i]; for(i=1,k=1,j=i+1;j<=n;j++) { if(t-a[i]==t-a[j]) continue; k++; a[k]=a[j]; i=j; } printf("\n Array after removing the duplicates"); for(i=1;i<=k;i++) printf(" %d",a[i]); }
Similar Threads
- remove duplicates in a sorted array (C)
- Check my code: Get ten random unique numbers then store in array. (C)
- extracting only the unique rows - please help (Shell Scripting)
- displaying data from a sorted array (C++)
- Printing a sorted array. (VB.NET)
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork function getlasterror getlogicaldrivestrin givemetehcodez global grade gtkgcurlcompiling gtkwinlinux hacking hardware highest histogram ide include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping lowest match matrix meter microsoft motherboard mqqueue number odf opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi



