1.急急急!!!如何用VB实现磁盘扫描的NStepScan算法
2.vb问题:希望可以给代码
急急急!!!如何用VB实现磁盘扫描的NStepScan算法
c的,网上搜的源码之心。
#include "stdafx.h"
#include "stdlib.h"
int L,boost 只是用源码P;
int a[];
int flag;//访问位
typedef struct TASK
{
int requrie;
int io;
} TASK;
TASK T[][];
TASK N[];
int diskway;//当前磁道
void iodowith();
void init()
{
int i,j;
for(i=0;i<;i++)
{
for(j=0;j<;j++)
{
T[i][j].requrie=-1;
}
}
for(i=0;i<L;i++)
{
for(j=0;j<P;j++)
{
T[i][j].requrie=rand()%;
T[i][j].io=rand()%2;
}
}
}
void output()
{
printf("磁盘访问的初始顺序是:\n");
for(int i=0;i<L;i++)
{
printf("第%d组是:\n",i+1);
for(int j=0;j<P;j++)
{
printf("%d %d\t",T[i][j].requrie,T[i][j].io);
}
printf("\n");
}
}
void sort_btos(TASK x[],int n)
{
int i,j,k;
TASK t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(x[j].requrie>x[k].requrie)
k=j;
if(k!=i)
{
t=x[i];
x[i]=x[k];
x[k]=t;
}
}
}
void sort_stob(TASK x[],int n)
{ int i,j,k;
TASK t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(x[j].requrie<x[k].requrie)
k=j;
if(k!=i)
{
t=x[i];
x[i]=x[k];
x[k]=t;
}
}
}
void SortInToOut(TASK x[],int nowdiskway,int num)
{
TASK a[],b[];
int s=0,t=0;
for(int i=0;i<num;i++)
{
if(x[i].requrie>=nowdiskway)
{
a[t]=x[i];
t++;
}
else
{
b[s]=x[i];
s++;
}
}
sort_stob(a,t);
sort_btos(b,s);
for(i=0;i<t;i++)
{
x[i]=a[i];
}
for(i=t;i<num;i++)
{
x[i]=b[i-t];
}
}
void SortOutToIn(TASK x[],int nowdiskway,int num)
{
TASK a[],b[];
int s=0,t=0;
for(int i=0;i<num;i++)
{
if(x[i].requrie<=nowdiskway)
{
a[t]=x[i];
t++;
}
else
{
b[s]=x[i];
s++;
}
}
sort_btos(a,t);
sort_stob(b,s);
for(i=0;i<t;i++)
{
x[i]=a[i];
}
for(i=t;i<num;i++)
{
x[i]=b[i-t];
}
}
void iodowith()
{
int p=P;
a[0]=p;
for(int i=0;i<L;i++)
{
if(i==L-1)
{
p=0;
for(int j=0;j<P;j++)
{
if(T[i][j].io==1)
{
T[i+1][p].requrie=rand()%;
printf("在第%d队第%d行设定io请求%d\n",i+1,j+1,T[i+1][p].requrie);
p++;
}
a[i+1]=p;
}
}
else
{
p=P;
for(int j=0;j<P;j++)
{
if(T[i][j].io==1)
{
T[i+1][p].requrie=rand()%;
printf("在第%d队第%d行设定io请求%d\n",i+1,j+1,T[i+1][p].requrie);
p++;
}
}
a[i+1]=p;
}
}
}
void NStepScan()
{
int D[];
int M;
TASK Y[];
printf("-----------------------------------------------------\n");
printf("next disk number\tmove distance\n");
for(int i=0;i<L+1;i++)
{
M=a[i];
for(int j=0;j<M;j++)
{
N[j]=T[i][j];
}
if(i==0)
{
if(flag==1)
SortInToOut(N,diskway,M);
else
{ SortOutToIn(N,diskway,M);}
for(int j=0;j<M;j++)
{
Y[j]=N[j];
}
}
else
{
if(Y[a[i-1]-2].requrie<Y[a[i-1]-1].requrie)
{
SortInToOut(N,diskway,M);
}
else
{
SortOutToIn(N,diskway,M);
}
for(int j=0;j<M;j++)
{
Y[j]=N[j];
}
}
D[0]=abs(diskway-N[0].requrie);
for(int t=1;t<M;t++)
{
D[t]=abs(N[t].requrie-N[t-1].requrie);
}
printf("-----------------------------------------------------\n");
printf("第%d组的情况:\n",i+1);
for(t=0;t<M;t++)
{
printf("\t%3d\t\t\t%3d\n",N[t].requrie,D[t]);
}
diskway=N[M-1].requrie;
}
}
int main(int argc, char* argv[])
{
printf("n-STEP-SCAN算演示!\n");
printf("随机产生小于的磁道号\n");
printf("请输入队列个数 队列中磁道个数 输入当前磁道号(0-)\n");
printf("请设定此时磁盘访问的方向(1.从里向外 2.从外向里)\n");
scanf("%d%d%d%d",&L,&P,&diskway,&flag);
init();
output();
iodowith();
NStepScan();
return 0;
}
vb问题:希望可以给代码
先新建一个模块,里面添加API声明
Option Explicit
Declare Function MoveWindow Lib "user" (ByVal hwnd As Long,黑页业务源码 ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function SendMessage Lib "user" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const LB_INITSTORAGE = &H1A8
Public Const LB_ADDSTRING = &H
Public Const WM_SETREDRAW = &HB
Public Const WM_VSCROLL = &H
Public Const SB_BOTTOM = 7
Declare Function GetLogicalDrives Lib "kernel" () As Long
Declare Function FindFirstFile Lib "kernel" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN_FIND_DATA) As Long
Public Const INVALID_HANDLE_VALUE = -1
Declare Function FindNextFile Lib "kernel" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN_FIND_DATA) As Long
Declare Function FindClose Lib "kernel" (ByVal hFindFile As Long) As Long
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Const MaxLFNPath =
Type WIN_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MaxLFNPath
cShortFileName As String *
End Type
然后在窗体上制作2个菜单,放置一个ListBox和一个PictureBox
完整代码如下:
Option Explicit
Dim PicHeight%,asp网站源码破解 hLB&, FileSpec$, UseFileSpec%
Dim TotalDirs%, TotalFiles%, Running%
Dim WFD As WIN_FIND_DATA, hItem&, hFile&
Const vbBackslash = "\"
Const vbAllFiles = "*.*"
Const vbKeyDot =
Private Sub Form_Load()
ScaleMode = vbPixels
PicHeight% = Picture1.Height
hLB& = List1.hwnd
SendMessage hLB&, LB_INITSTORAGE, &, ByVal & *
Move (Screen.Width - Width) * 0.5, (Screen.Height - Height) * 0.5
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape And Running% Then Running% = False
End Sub
Private Sub Form_Resize()
MoveWindow hLB&, 0, 0, ScaleWidth, ScaleHeight - PicHeight%, True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End
End Sub
Private Sub mnuFindFiles_Click()
If Running% Then: Running% = False: Exit Sub
Dim drvbitmask&, maxpwr%, pwr%
On Error Resume Next
FileSpec$ = InputBox("Enter a file spec:" & vbCrLf & vbCrLf & "Searching will begin at drive A and continue " & "until no more drives are found. " & "Click Stop! at any time." & vbCrLf & "The * and ? wildcards can be used.", "Find File(s)", "*.exe")
If Len(FileSpec$) = 0 Then Exit Sub
MousePointer =
Running% = True
UseFileSpec% = True
mnuFindFiles.Caption = "&Stop!"
mnuFolderInfo.Enabled = False
List1.Clear
drvbitmask& = GetLogicalDrives()
If drvbitmask& Then
maxpwr% = Int(Log(drvbitmask&) / Log(2))
For pwr% = 0 To maxpwr%
If Running% And (2 ^ pwr% And drvbitmask&) Then _
Call SearchDirs(Chr$(vbKeyA + pwr%) & ":\")
Next
End If
Running% = False
UseFileSpec% = False
mnuFindFiles.Caption = "&Find File(s)..."
mnuFolderInfo.Enabled = True
MousePointer = 0
Picture1.Cls
Picture1.Print "Find File(s): " & List1.ListCount & " items found matching " & """" & FileSpec$ & """"
Beep
End Sub
Private Sub mnuFolderInfo_Click()
If Running% Then: Running% = False: Exit Sub
Dim searchpath$
On Error Resume Next
searchpath$ = InputBox("输入要查找的目标路径", "文件夹信息", "C:\")
If Len(searchpath$) < 2 Then Exit Sub
If Mid$(searchpath$, 2, 1) <> ":" Then Exit Sub
If Right$(searchpath$, 1) <> vbBackslash Then searchpath$ = searchpath$ & vbBackslash
If FindClose(FindFirstFile(searchpath$ & vbAllFiles, WFD)) = False Then
End If
MousePointer =
Running% = True
mnuFolderInfo.Caption = "停止(&S)"
mnuFindFiles.Enabled = False
List1.Clear
TotalDirs% = 0
TotalFiles% = 0
Call SearchDirs(searchpath$)
Running% = False
mnuFolderInfo.Caption = "文件夹信息(&F)"
mnuFindFiles.Enabled = True
Picture1.Cls
MousePointer = 0
MsgBox "Total folders: " & vbTab & TotalDirs% & vbCrLf & "Total files: " & vbTab & TotalFiles%, , "Folder Info for: " & searchpath$
End Sub
Private Sub SearchDirs(curpath$)
Dim dirs%, dirbuf$(), i%
Picture1.Cls
Picture1.Print "Searching " & curpath$
DoEvents
If Not Running% Then Exit Sub
hItem& = FindFirstFile(curpath$ & vbAllFiles, WFD)
If hItem& <> INVALID_HANDLE_VALUE Then
Do
If (WFD.dwFileAttributes And vbDirectory) Then
If Asc(WFD.cFileName) <> vbKeyDot Then
TotalDirs% = TotalDirs% + 1
If (dirs% Mod ) = 0 Then ReDim Preserve dirbuf$(dirs% + )
dirs% = dirs% + 1
dirbuf$(dirs%) = Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
End If
ElseIf Not UseFileSpec% Then
TotalFiles% = TotalFiles% + 1
End If
Loop While FindNextFile(hItem&, WFD)
Call FindClose(hItem&)
End If
If UseFileSpec% Then
SendMessage hLB&, WM_SETREDRAW, 0, 0
Call SearchFileSpec(curpath$)
SendMessage hLB&, WM_VSCROLL, SB_BOTTOM, 0
SendMessage hLB&, WM_SETREDRAW, 1, 0
End If
For i% = 1 To dirs%: SearchDirs curpath$ & dirbuf$(i%) & vbBackslash: Next i%
End Sub
Private Sub SearchFileSpec(curpath$)
hFile& = FindFirstFile(curpath$ & FileSpec$, WFD)
If hFile& <> INVALID_HANDLE_VALUE Then
Do
DoEvents
If Not Running% Then Exit Sub
SendMessage hLB&, LB_ADDSTRING, 0, ByVal curpath$ & Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
Loop While FindNextFile(hFile&, WFD)
Call FindClose(hFile&)
End If
End Sub
程序运行时就能够通过输入文件名而进行模糊查找了
如果还不明白,就加我QQ,linux kernel 源码阅读我把我做好的程序发给你看
QQ号: