Commit 3c67903d authored by indiana.brown's avatar indiana.brown

First commit

parents
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
public class LinearSearch{
public static void Main(String[] args){
StreamReader file = new StreamReader("million.txt");
string line;
string search;
string[] separator = {"<SEP>"};
string artist;
string title;
//List<string> songs = new List<string>();
List<Song> songs = new List<Song>();
//Writes file to memory
// while((line = file.ReadLine()) != null){
// string[] parts = line.Split(separator, StringSplitOptions.None);
// artistsong = (parts[2] + " - " + parts[3]);
// songs.Add(artistsong);
// }
while((line = file.ReadLine()) != null){
string[] parts = line.Split(separator, StringSplitOptions.None);
artist = parts[2];
title = parts[3];
songs.Add(new Song(title, artist));
}
Stopwatch swatch = new Stopwatch();
//Prompts user input
Console.WriteLine("Enter a song name: ");
search = Console.ReadLine();
//Returns results based on user input
Console.WriteLine("\nResults for " + search + ":");
swatch.Start();
foreach (Song s in songs) {
if (s.title == search) {
Console.WriteLine("\n" + s.artist + " - " + s.title);
}
}
swatch.Stop();
//Prints elapsed time for searching
Console.WriteLine("\nTime elapsed : {0} milliseconds", swatch.ElapsedMilliseconds);
// while((line = file.ReadLine()) != null){
// string[] parts = line.Split(separator, StringSplitOptions.None);
// foreach (var part in parts){
// Console.WriteLine(part);
// }
//Console.ReadLine();
// Console.WriteLine("Read line: " + );
// Console.ReadLine();
//}
}
}
File added
using System;
using System.IO;
using System.Collections.Generic;
public class Song{
public Song(string title_, string artist_){
// line = line_;
title = title_;
artist = artist_;
}
// public string line;
public string title;
public string artist;
// string[] separator = {"<SEP>"};
// List<Song> songs = new List<Song>();
// public static void memAdd(){
// while((line = file.ReadLine()) != null){
// string[] parts = line.Split(separator, StringSplitOptions.None);
// foreach (var part in parts){
// songs.Add(new Song(title, artist));
// Console.WriteLine(part);
// }
// }
// }
};
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment