① c語言 單鏈表源代碼
#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
typedef char ElemType;
struct LNode
{
ElemType data;
struct LNode *next;
};
//***********************************************************置空表setnull()
void setnull(struct LNode **p)
{
*p=NULL;
}
//************************************************************求長度length()
int length(struct LNode **p)
{
int n=0;
struct LNode *q=*p;
while (q!=NULL)
{
n++;
q=q->next;
}
return(n);
}
//*************************************************************取結點get()
ElemType get(struct LNode **p,int i)
{
int j=1;
struct LNode *q=*p;
while (j<i && q!=NULL) /**//*查找第i個結點*/
{
q=q->next;j++;
}
if (q!=NULL) /**//*找到了第i個結點*/
return(q->data);
else
{
printf("位置參數不正確!\n");
return NULL;
}
}
//************************************************************按值查找locate()
int locate(struct LNode **p,ElemType x)
{
int n=0;
struct LNode *q=*p;
while (q!=NULL && q->data!=x) /**//*查找data域為x的第一個結點*/
{
q=q->next;
n++;
}
if (q==NULL) /**//*未找到data域等於x的結點*/
return(-1);
else /**//*找到data域等於x的結點*/
return(n+1);
}
//**********************************************************插入結點insert()
void insert(struct LNode **p,ElemType x,int i)
{
int j=1;
struct LNode *s,*q;
s=(struct LNode *)malloc(sizeof(struct LNode)); /**//*建立要插入的結點s*/
s->data=x;
q=*p;
if (i==1) /**//*插入的結點作為頭結點*/
{
s->next=q;
*p=s;
}
else
{
while (j<i-1 && q->next!=NULL) /**//*查找第i-1個結點*/
{
q=q->next;j++;
}
if (j==i-1) /**//*找到了第i-1個結點,由q指向它*/
{
s->next=q->next; /**//*將結點s插入到q結點之後*/
q->next=s;
}
else
printf("位置參數不正確!\n");
}
}
//*********************************************************刪除結點del()
void del(struct LNode **p,int i)
{
int j=1;
struct LNode *q=*p,*t;
if (i==1) /**//*刪除鏈表的頭結點*/
{
t=q;
*p=q->next;
}
else
{
while (j<i-1 && q->next!=NULL) /**//*查找第i-1個結點*/
{
q=q->next;j++;
}
if (q->next!=NULL && j==i-1) /**//*找到第i-1個結點,由q指向它*/
{
t=q->next; /**//*t指向要刪除的結點*/
q->next=t->next; /**//*將q之後的結點刪除*/
}
else printf("位置參數不正確!\n");
}
if (t!=NULL) /**//*在t不為空時釋放該結點*/
free(t);
}
//********************************************************顯示鏈表display()
void display(struct LNode **p)
{
struct LNode *q;
q=*p;
printf("單鏈表顯示:");
if (q==NULL) /**//*鏈表為空時*/
printf("鏈表為空!");
else if (q->next==NULL) /**//*鏈表只有一個結點時*/
printf("%c\n",q->data);
else { /**//*鏈表存在一個以上的結點時*/
while (q->next!=NULL) /**//*顯示前面的結點*/
{
printf("%c→",q->data);q=q->next;
}
printf("%c",q->data); /**//*顯示最後一個結點*/
}
printf("\n");
}
void main()
{
struct LNode *head;
setnull(&head);
insert(&head,'a',1);
insert(&head,'b',2);
insert(&head,'a',2);
insert(&head,'c',4);
insert(&head,'d',3);
insert(&head,'e',1);
display(&head);
printf("單鏈表長度=%d\n",length(&head));
printf("位置:%d 值:%c\n",3,get(&head,3));
printf("值:%c 位置:%d\n",'a',locate(&head,'a'));
printf("刪除第1個結點:");
del(&head,1);
display(&head);
printf("刪除第5個結點:");
del(&head,5);
display(&head);
printf("刪除開頭3個結點:");
del(&head,3);
del(&head,2);
del(&head,1);
display(&head);
}
/**//*
運行結果:
單鏈表顯示:e→a→a→d→b→c
單鏈表長度=6
位置:3 值:a
值:a 位置:2
刪除第1個結點:單鏈表顯示:a→a→d→b→c
刪除第5個結點:單鏈表顯示:a→a→d→b
刪除開頭3個結點:單鏈表顯示:b
*/
② 關於哪位有C#與三菱PLC通訊的源碼,最好有實例
C#與三菱PLC通訊的源碼
1) 文件校驗
我們比較熟悉的校驗演算法有奇偶校驗和CRC校驗,這2種校驗並沒有抗數據篡改的能力,它們一定程度上能檢測並糾正數據傳輸中的信道誤碼,但卻不能防止對數據的惡意破壞。
MD5 Hash演算法的"數字指紋"特性,使它成為目前應用最廣泛的一種文件完整性校驗和(Checksum)演算法,不少Unix系統有提供計算md5 checksum的命令。
2) 數字簽名
Hash 演算法也是現代密碼體系中的一個重要組成部分。由於非對稱演算法的運算速度較慢,所以在數字簽名協議中,單向散列函數扮演了一個重要的角色。 對 Hash 值,又稱"數字摘要"進行數字簽名,在統計上可以認為與對文件本身進行數字簽名是等效的。而且這樣的協議還有其他的優點。
3) 鑒權協議
如下的鑒權協議又被稱作"挑戰--認證模式:在傳輸信道是可被偵聽,但不可被篡改的情況下,這是一種簡單而安全的方法。
③ 高分求一段J2ME源代碼
import javax.microedition.lci.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.io.*;
public class PlayerMIDlet extends MIDlet implements CommandListener {
private Display display;
private List lst;
private Command start = new Command("Play",Command.SCREEN, 1);
private Command exit = new Command("Exit",Command.EXIT,2);
int currentPlaying = -1;
//Sound Player object.
static Player bbsounds[];
private Player tonePlayer;
public PlayerMIDlet(){
display = Display.getDisplay(this);
sound_init();
createTonePlayer();
}
protected void startApp() {
String[] elements = {"Play >> airhorn.wav","Play >> intro.midi","Play >> TuneSequence"};
lst = new List("Menu", List.IMPLICIT, elements, null);
lst.setCommandListener(this);
lst.addCommand(start);
display.setCurrent(lst);
}
private void reset(){
}
protected void pauseApp() {
try {
if(bbsounds[currentPlaying] != null && bbsounds[currentPlaying].getState() == bbsounds[currentPlaying].STARTED) {
bbsounds[currentPlaying].stop();
} else {
defplayer();
}
}catch(MediaException me) {
reset();
}
}
protected void destroyApp(boolean unconditional) {
lst = null;
try {
defplayer();
}catch(MediaException me) { }
}
public void commandAction(Command c , Displayable d){
int index = lst.getSelectedIndex();
System.out.println("Playing Sound .....");
if(c == start){
if (index == 0){
sound_play(0);
}
if(index == 1){
sound_play(1);
}
if(index == 2){
playTones();
}
}
if(c == exit){
this.destroyApp(true);
}
}
void defplayer() throws MediaException {
try{
if (bbsounds[currentPlaying] != null) {
if(bbsounds[currentPlaying].getState() == bbsounds[currentPlaying].STARTED) {
bbsounds[currentPlaying].stop();
}
if(bbsounds[currentPlaying].getState() == bbsounds[currentPlaying].PREFETCHED) {
bbsounds[currentPlaying].deallocate();
}
if(bbsounds[currentPlaying].getState() == bbsounds[currentPlaying].REALIZED ||
bbsounds[currentPlaying].getState() == bbsounds[currentPlaying].UNREALIZED) {
bbsounds[currentPlaying].close();
}
}
bbsounds = null;
}catch(Exception e){
}
}
public void sound_init()
{
try
{
bbsounds = new Player[ 3 ];
InputStream in = getClass().getResourceAsStream("airhorn.wav");
try
{
bbsounds[0] = Manager.createPlayer(in, "audio/X-wav");
}catch( Exception e ){
//System.out.println("Exception in Sound Creation ");
}
in = null;
InputStream is = getClass().getResourceAsStream("intro.midi");
try
{
bbsounds[1] = Manager.createPlayer(is, "audio/midi");
is = null;
}catch( Exception e ){
//System.out.println("Exception in Sound Creation ");
}
}catch( Exception e){}
}
public void sound_play(int id)
{
//System.out.println("Playing ID is >>"+id);
sound_stop( currentPlaying );
currentPlaying = id;
try
{
bbsounds[ id ].realize();
System.out.println("Playing Sound...");
bbsounds[ id ].start();
}catch(Exception e){
//System.out.println("Playing Exception");
}
return;
}
public void sound_stop( int id)
{
try{
if(id!=-1){
bbsounds[ id ].deallocate();
bbsounds[ id ].stop();
tonePlayer.stop();
}
}catch(Exception ex){
//System.out.println("Stop Sound Exception ");
}
return;
}
private void createTonePlayer() {
/**
* "Mary Had A Little Lamb" has "ABAC" structure.
* Use block to repeat "A" section.
*/
byte tempo = 30; // set tempo to 120 bpm
byte d = 8; // eighth-note
byte C4 = ToneControl.C4;;
byte D4 = (byte)(C4 + 2); // a whole step
byte E4 = (byte)(C4 + 4); // a major third
byte G4 = (byte)(C4 + 7); // a fifth
byte rest = ToneControl.SILENCE; // rest
byte[] mySequence = {
ToneControl.VERSION, 1, // version 1
ToneControl.TEMPO, tempo, // set tempo
ToneControl.BLOCK_START, 0, // start define "A" section
E4,d, D4,d, C4,d, E4,d, // content of "A" section
E4,d, E4,d, E4,d, rest,d,
ToneControl.BLOCK_END, 0, // end define "A" section
ToneControl.PLAY_BLOCK, 0, // play "A" section
D4,d, D4,d, D4,d, rest,d, // play "B" section
E4,d, G4,d, G4,d, rest,d,
ToneControl.PLAY_BLOCK, 0, // repeat "A" section
D4,d, D4,d, E4,d, D4,d, C4,d // play "C" section
};
try{
tonePlayer = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
tonePlayer.realize();
ToneControl c = (ToneControl)tonePlayer.getControl("ToneControl");
c.setSequence(mySequence);
} catch (IOException ioe) {System.err.println("Initializing Tone");}
catch (MediaException me) { }
}
public void playTones() {
if (tonePlayer != null){
try {
System.out.println("Playing Sound...");
tonePlayer.prefetch();
tonePlayer.start();
} catch (MediaException me) {
//System.err.println("Problem starting player");
} // end catch
} // end if
} // end playTone
}
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lci.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class AudioMidlet extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private List main;
Player player=null;
VolumeControl vc;
public void startApp() {
mDisplay = Display.getDisplay(this);
main = new List("AudioMIDlet", List.IMPLICIT);
main.append("music1", null);
main.append("music2", null);
main.append("music3", null);
main.addCommand(new Command("Exit", Command.EXIT, 0));
main.addCommand(new Command("Play", Command.SCREEN, 0));
main.setCommandListener(this);
mDisplay.setCurrent(main);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
else {
Form waitForm = new Form("Loading...");
mDisplay.setCurrent(waitForm);
Thread t = new Thread(this);
t.start();
}
}
public void run() {
playFromResource();
}
private void playFromResource() {
try {
int i=main.getSelectedIndex();
InputStream in=null;
switch(i)
{
case 0:
in = getClass().getResourceAsStream("/chimes.wav");
player = Manager.createPlayer(in, "audio/x-wav");
player.start();
break;
case 1:
in = getClass().getResourceAsStream("/chord.wav");
player = Manager.createPlayer(in, "audio/x-wav");
player.start();
break;
case 2:
in = getClass().getResourceAsStream("/music.wav");
player = Manager.createPlayer(in,"audio/x-wav");
player.start();
break;
}
}
catch (Exception e) {
showException(e);
return;
}
mDisplay.setCurrent(main);
}
private void showException(Exception e) {
Alert a = new Alert("Exception", e.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, main);
}
}
//把上面兩個java文件放在一個包里,我的是在Netbeans里編的,還要屬性里改一下,就是在MIDlet里增加一下
//另外你要播放什麼文件自己加在包里,程序里你也可以適當改一下參數
④ 單片機裡面.HEX文件不是由.C文件生成的嗎為什麼有的程序裡面.C文件與.hex文件的文件名不一致
.UVproj是項目文件,裡麵包含項目內的所有源文件的登記、編譯器相關設置、以及生成目標的配置等一些列信息;hex則是項目生成的最終程序,是項目中所有code編譯鏈接得到的,所以.UVproj文件和hex文件應該是同名的。.c文件是源文件,obj是c文件編譯得到的,他們的文件名肯定相同。一個項目中可以含有很多源代碼文件(通常是c或者匯編文件),每個源文件只實現項目的一部分功能,所以單個c文件不能代表整個項目,所以c文件的名字不需要和hex文件相同。
⑤ dsp中.lst文件包含哪些信息
html是超文本標記語言,標准通用標記語言下的一個應用。
「超文本」就是指頁面內可以包含圖片、鏈接,甚至音樂、程序等非文字元素。
超文本標記語言的結構包括「頭」部分(英語:Head)、和「主體」部分(英語:Body),其中「頭」部提供關於網頁的信息,「主體」部分提供網頁的具體內容。
由以上可以說明html後綴名的文件是網頁文件,用瀏覽器打開就可以看到網頁,以文本格式打開,就可以看到該網頁的源碼
⑥ 求C#與三菱Q系列PLC 通訊實例或源碼
⑦ 在keil中如何實現C語言中嵌入匯編
你不是就想得到匯編源碼嗎?在OptionsforTarget-->Listing標簽頁下,在CCompilerListing:\*.lst部分中勾選AssemblyCode,這樣生成的LST文件中就會包含匯編源碼了。
⑧ menu.lst的寫法問題 電腦愛好者2014年3月上
我配的是雙系統,不過很多年前配的了,這陣都有點記不到具體的意思了,文件貼給你
default=1
timeout=4
gfxmenu (hd0,6)/message
title RedFlag (2.6.22.6-1)
root (hd0,6)
kernel /vmlinuz-2.6.22.6-1 ro root=LABEL=/1 vga=788 splash=silent resume=/dev/sda9
initrd /initrd-2.6.22.6-1.img
title Other
rootnoverify (hd0,0)
chainloader +1
⑨ 求FTP CLIENT源碼(java)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.StringTokenizer;
import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;
public class FtpClientDemo {
public static int BUFFER_SIZE = 10240;
private FtpClient m_client;
// set the values for your server
private String host = "";
private String user = "";
private String password = "";
private String sDir = "";
private String m_sLocalFile = "";
private String m_sHostFile = "";
public FtpClientDemo() {
try {
System.out.println("Connecting to host " + host);
m_client = new FtpClient(host);
m_client.login(user, password);
System.out.println("User " + user + " login OK");
System.out.println(m_client.welcomeMsg);
m_client.cd(sDir);
System.out.println("Directory: " + sDir);
m_client.binary();
System.out.println("Success.");
} catch (Exception ex) {
System.out.println("Error: " + ex.toString());
}
}
protected void disconnect() {
if (m_client != null) {
try {
m_client.closeServer();
} catch (IOException ex) {
}
m_client = null;
}
}
public static int getFileSize(FtpClient client, String fileName)
throws IOException {
TelnetInputStream lst = client.list();
String str = "";
fileName = fileName.toLowerCase();
while (true) {
int c = lst.read();
char ch = (char) c;
if (c < 0 || ch == '\n') {
str = str.toLowerCase();
if (str.indexOf(fileName) >= 0) {
StringTokenizer tk = new StringTokenizer(str);
int index = 0;
while (tk.hasMoreTokens()) {
String token = tk.nextToken();
if (index == 4)
try {
return Integer.parseInt(token);
} catch (NumberFormatException ex) {
return -1;
}
index++;
}
}
str = "";
}
if (c <= 0)
break;
str += ch;
}
return -1;
}
protected void getFile() {
if (m_sLocalFile.length() == 0) {
m_sLocalFile = m_sHostFile;
}
byte[] buffer = new byte[BUFFER_SIZE];
try {
int size = getFileSize(m_client, m_sHostFile);
if (size > 0) {
System.out.println("File " + m_sHostFile + ": " + size
+ " bytes");
System.out.println(size);
} else
System.out.println("File " + m_sHostFile + ": size unknown");
FileOutputStream out = new FileOutputStream(m_sLocalFile);
InputStream in = m_client.get(m_sHostFile);
int counter = 0;
while (true) {
int bytes = in.read(buffer);
if (bytes < 0)
break;
out.write(buffer, 0, bytes);
counter += bytes;
}
out.close();
in.close();
} catch (Exception ex) {
System.out.println("Error: " + ex.toString());
}
}
protected void putFile() {
if (m_sLocalFile.length() == 0) {
System.out.println("Please enter file name");
}
byte[] buffer = new byte[BUFFER_SIZE];
try {
File f = new File(m_sLocalFile);
int size = (int) f.length();
System.out.println("File " + m_sLocalFile + ": " + size + " bytes");
System.out.println(size);
FileInputStream in = new FileInputStream(m_sLocalFile);
OutputStream out = m_client.put(m_sHostFile);
int counter = 0;
while (true) {
int bytes = in.read(buffer);
if (bytes < 0)
break;
out.write(buffer, 0, bytes);
counter += bytes;
System.out.println(counter);
}
out.close();
in.close();
} catch (Exception ex) {
System.out.println("Error: " + ex.toString());
}
}
public static void main(String argv[]) {
new FtpClientDemo();
}
}