using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
List<person> persons = new List<person>();
//database records entring
person
p = new person();
//1st
record
p.id =
1;
p.firstName = "Aoun";
p.lastName = "Ali";
p.age =
22;
p.address = "Pakistan, karachi";
persons.Add(p);
//2nd
record
p = new
person();
p.id =
2;
p.firstName = "Marium";
p.lastName = "Hussain";
p.age =
22;
p.address = "Pakistan, Karachi";
persons.Add(p);
//3rd
record
p = new
person();
p.id =
3;
p.firstName = "Osama";
p.lastName = "Ali";
p.age =
23;
p.address = "Pakistan, karachi";
persons.Add(p);
//4th
record
p = new
person();
p.id =
4;
p.firstName = "Ayesha ";
p.lastName = "Ejaz";
p.age =
22;
p.address = "Pakistan, karachi";
persons.Add(p);
//5th
record
p = new
person();
p.id =
5;
p.firstName = "Adnan";
p.lastName = "Naseer";
p.age =
23;
p.address = "Pakistan, karachi";
persons.Add(p);
//6th
record
p = new
person();
p.id =
6;
p.firstName = "Raheel";
p.lastName = "Malik";
p.age =
23;
p.address = "Pakistan, islamabad";
persons.Add(p);
//7th record(redundant)
p = new
person();
p.id =
7;
p.firstName = "Aoun";
p.lastName = "Ali";
p.age =
22;
p.address = "Pakistan, karachi";
persons.Add(p);
//8th record(redundant)
p = new
person();
p.id =
8;
p.firstName = "Marium";
p.lastName = "Hussain";
p.age =
22;
p.address = "Pakistan, Karachi";
persons.Add(p);
//9th
record(redundant)
p = new
person();
p.id =
9;
p.firstName = "Ayesha";
p.lastName = "Ejaz";
p.age =
23;
p.address = "Pakistan, karachi";
persons.Add(p);
//10th
record(redundant)
p = new
person();
p.id =
10;
p.firstName = "Osama";
p.lastName = "Ali";
p.age =
23;
p.address = "Pakistan, karachi";
persons.Add(p);
//DATABASE END
//display record
Console.WriteLine("ID
First_Name Last_Name age
Address");
for(int
i=0; i<persons.Count ; i++)
{
Console.WriteLine(persons[i].id + " " + persons[i].firstName +
" " +
persons[i].lastName + "
" + persons[i].age + " " + persons[i].address);
}
Console.WriteLine("\n\n\n\n");
List<string> key = new List<string>();
//MAKING KEY BY CONCATENATING THE IMPORTANT COLUMNS ( I CHOOSE
FIRST_NAME, AGE, ADDRESS)
foreach
(person pi in persons)
{
key.Add(pi.firstName + pi.age.ToString() + pi.address);
}
//SORT
THE KEY FIRST
key.Sort();
//MAKING SORTED LIST ON THE BASIS OF SORTED KEY SO THAT REDUNDANT
RECORDS COME NEXT TO EACH OTHER
List<person> sortedlist = new List<person>();
for
(int i = 0; i < persons.Count; i++)
{
foreach (person pi in persons)
{
if (key[i] == (pi.firstName + pi.age.ToString() + pi.address))
{
sortedlist.Add(pi);
break;
}
}
}
Console.WriteLine("\n\n\n\n");
//remove redundant data from sorted list
for
(int i = 0; i < sortedlist.Count - 1; i++)
{
string record1 = sortedlist[i].firstName + sortedlist[i].age.ToString()
+ sortedlist[i].address;
string record2 = sortedlist[i + 1].firstName + sortedlist[i +
1].age.ToString() + sortedlist[i + 1].address;
if (record1 == record2)
sortedlist.Remove(sortedlist[i]);
}
Console.WriteLine("After Applied BSN");
Console.WriteLine("ID
First_Name Last_Name age
Address");
for (int i = 0; i < sortedlist.Count;
i++)
{
Console.WriteLine(sortedlist[i].id + " " + sortedlist[i].firstName +
" " + sortedlist[i].lastName
+ " " + persons[i].age +
" " + persons[i].address);
}
Console.ReadKey();
}
}
class person
{
public int
id;
public
string firstName;
public
string lastName;
public int
age;
public
string address;
}
}
Output:
Before
BSN:
After BSN:
I m also Giving a video reference This is in urdu Language from Virtual university ,Lecture of dataware housing.


No comments:
Post a Comment