代碼200行c語言,200行的代碼

本文目錄一覽:

C語言課程設計不少於200行代碼

#include “stdio.h”

#include”stdlib.h”

#include “conio.h”

#include”string.h”

struct SStudent

{

unsigned number;

char name[10];

char tele[12];

struct SStudent * link;

};

void main()

{

struct SStudent * CreateTable();

void AppendToTable(struct SStudent * stu);

void InsertToTable(struct SStudent * stu);

void QueryTable(struct SStudent * stu, unsigned number);

void SortTable(struct SStudent * stu);

void PrintTable(struct SStudent * stu);

void Save(struct SStudent * stu);

void Load(struct SStudent * stu);

void Help();

void modi(struct SStudent *h);

void search(struct SStudent *h);struct SStudent * student;

unsigned number;

char keyValue;

student = CreateTable();

//clrscr();

system(“cls”);

Help();

printf(“\n= “);

while((keyValue = getche()) != ‘q’ keyValue != ‘Q’ keyValue != 27)

{

puts(“”);

switch(keyValue)

{

case ‘l’: case ‘L’:

PrintTable(student); break;

case ‘d’: case ‘D’:

printf(“Please input the number you want delete: “);

scanf(“%d”, number);

QueryTable(student, number);

break;

case ‘a’: case ‘A’:

AppendToTable(student); break;

case ‘i’: case ‘I’:

InsertToTable(student); break;

case ‘s’: case ‘S’:

SortTable(student);

puts(“Sort complished! Please use command L to list.”);

break;

case ‘f’: case ‘F’:

search(student);

break;

case ‘m’: case ‘M’:

modi(student);

break;case ‘v’: case ‘V’:

Save(student); break;

case ‘o’: case ‘O’:

Load(student); break;

case ‘h’: case ‘H’:

Help(); break;

default: puts(“Error command!”);

}

printf(“\n= “);

}

}

struct SStudent * CreateTable()

{

struct SStudent * stu;

stu = (struct SStudent *) malloc(sizeof(struct SStudent));

stu-number = 0;

stu-name[0] = ‘\0’;

stu-tele[0] = ‘\0’;

stu-link = NULL;

return(stu);

}

void AppendToTable(struct SStudent * stu)

{

struct SStudent * next, * last;

int number;

last = stu;

while(last-link) last = last-link;

printf(“Please input the number (0 to quit): “);

scanf(“%d”, number);

while(number)

{

next = (struct SStudent *) malloc(sizeof(struct SStudent));

next-number = number;

printf(“Please input name: “);

scanf(“%s”, next-name);

printf(“Please input tele: “);

scanf(“%s”, next-tele);

last-link = next;

last = last-link;

printf(“\nPlease input the number (0 to quit): “);

scanf(“%d”, number);

}

last-link = NULL;

}

void InsertToTable(struct SStudent * stu)

{

struct SStudent * next, * last;

int number;

printf(“Please input the number (0 to quit): “);

scanf(“%d”, number);

while(number)

{

next = (struct SStudent *) malloc(sizeof(struct SStudent));

next-number = number;

printf(“Please input name: “);

scanf(“%s”, next-name);

printf(“Please input tele: “);

scanf(“%s”, next-tele);

last = stu;

while(last-link)

{

if(last-link-number next-number)

{

next-link = last-link;

last-link = next;

break;

}

else last = last-link;

}

printf(“\nPlease input the number (0 to quit): “);

scanf(“%d”, number);

}

}

void QueryTable(struct SStudent * stu, unsigned number)

{

struct SStudent * temp, * next;

next = stu;

while(next-link)

{

if(next-link-number == number)

{

temp = next-link;

next-link = next-link-link;

free(temp);

}

else next = next-link;

}

}

void PrintTable(struct SStudent * stu)

{

stu = stu-link;

if(!stu)

{

puts(“The table is EMPTY!”);

return;

}

printf(“number\tname\ttele\n”);

while(stu)

{

printf(“%3d\t”, stu-number);

printf(“%-s\t”, stu-name);

printf(“%-s\t”, stu-tele);

printf(“\n”);

stu = stu-link;

}

}

void SortTable(struct SStudent * stu)

{

struct SStudent * next, * last, * temp;

int flag;

last = stu;

while(last-link)

{

next = stu; flag = 1;

while(next-link != last-link)

{

if(next-link-number last-link-number)

{

temp = last-link;

last-link = last-link-link;

temp-link = next-link;

next-link = temp;

flag = 0;

break;

}

else next = next-link;

}

if(flag) last = last-link;

}

}

void Save(struct SStudent * stu)

{

char filename[13];

FILE * fileSave;

printf(“Please input the filename you want save in: “);

scanf(“%s”, filename);

if((fileSave = fopen(filename, “wb”)) == 0)

{

printf(“Cannot open file %s !\n”, filename);

return;

}

puts(“Saveing …”);

stu = stu-link;

while(stu)

{

fwrite(stu, sizeof(struct SStudent), 1, fileSave);

stu = stu-link;

}

puts(“Saveing is finished!”);

}

void Load(struct SStudent * stu)

{char filename[13];brFILE * fileLoad;brstruct SStudent * temp;brwhile(stu-link)br{brtemp = stu-link;brstu-link = stu-link-link;brfree(temp);br}

temp = (struct SStudent *) malloc(sizeof(struct SStudent));

printf(“Please input the filename you want load from: “);

scanf(“%s”, filename);

if((fileLoad = fopen(filename, “rb”)) == 0)

{

printf(“Cannot open file %s !\n”, filename);

return;

}

puts(“Loading …”);

while(fread(temp, sizeof(struct SStudent), 1, fileLoad))

{stu-link = temp;brstu = stu-link;brtemp = (struct SStudent *) malloc(sizeof(struct SStudent));br}

stu-link = NULL;

puts(“loading is finished!”);

}

void Help()

{ puts(” *********************************************”);

puts(” * System Command Help *”);

puts(” *********************************************”);

puts(” * L = List all records *”);

puts(” * D = Delete a record seleced by number *”);

puts(” * A = Append records *”);

puts(” * I = Insert records *”);

puts(” * S = Sort records *”);

puts(” * F= Search records *”);

puts(” * M= Modi records *”);puts(” * H = Show this help message *”);

puts(” * V = Save records to a file *”);

puts(” * O = Load records from a file *”);

puts(” * Q = Quit System *”);

puts(” *********************************************”);

}

void modi(struct SStudent *h)

{

struct SStudent *p; /* 移動指針*/

unsigned num; /*存放學號的變量*/

// clrscr(); /*清屏幕*/

system(“cls”);

printf(“please enter number for modifi\n”);

scanf(“%d”,num); /*輸入學號*/

p=h; /*將頭指針賦給p*/

while( (p-number!=num)p!=NULL) /*當記錄的姓名不是要找的,且指針不為空時*/

p=p-link; /*移動指針,指向下一結點*/

if(p==NULL) /*如果指針為空*/

printf(“\nlist no %d student\n”,num); /*顯示沒有該學生*/

else /*修改找到的記錄信息*/

{

printf(“Please input new name: “);

scanf(“%s”, p-name);

printf(“Please input new tele: “);

scanf(“%s”, p-tele);

printf(“|number | name | tel | \n”);

printf(“|———-|—————|—————|\n”);

printf(“|%6d|%-10s|%12s|\n”, p-number,p-name,p-tele); }

}

void search(struct SStudent *h)

{

struct SStudent *p; /* 移動指針*/

char s[10]; /*存放姓名的字符數組*/

// clrscr(); /*清屏幕*/

system(“cls”);

printf(“please enter name for search\n”);

scanf(“%s”,s); /*輸入姓名*/

p=h; /*將頭指針賦給p*/

while(strcmp(p-name,s)p!=NULL) /*當記錄的姓名不是要找的,且指針不為空時*/

p=p-link; /*移動指針,指向下一結點*/

if(p==NULL) /*如果指針為空*/

printf(“\nlist no %s student\n”,s); /*顯示沒有該學生*/

else /*顯示找到的記錄信息*/

{

printf(“\n\n***********************havefound***********************\n”);

printf(“|number | name | tel | \n”);

printf(“|———-|—————|—————|\n”);

printf(“|%10d|%-10s|%12s|\n”, p-number,p-name,p-tele);

printf(“****************************end***************************\n”);

}

}

200行的c語言代碼,51單片機運行完要多長時間,沒有循環結構

如果沒有調用子程序的話,12M晶振時那麼執行時間大概是200~600微妙

急求啊,寫一個200行的C語言程序,什麼都可以,帶解釋,哪位大神幫幫忙

#include stdio.h

#define OK 1   

#define ERROR 0

#define TRUE 1   

#define FALSE 0

#define MAXSIZE 100

#define LElemType int

#define Status int

#define BOOL int

typedef struct

{

 LElemType data;

 int cur;

}Component,SLinkList[MAXSIZE];

int Malloc(SLinkList space) 

 //若備用鏈表非空,則返回分配的結點下標(備用鏈表的第一個結點),否則返回0

 int i=space[0].cur;

 if (i)

  space[0].cur=space[i].cur;

 return i;

}

Status Free(SLinkList space, int k) 

 //將下標為空的空閑結點回收到備用鏈表(成為備用鏈表的第一個結點)

 space[k].cur=space[0].cur;

 space[0].cur=k;

 return OK;

}

Status InitList(SLinkList L)

 //構造一個空的鏈表L,表頭為L的最後一個單元L[MAXSIZE-1],其餘單元鏈成

 //一個備用鏈表,表頭為L的第一個單元L[0],“0”表示空指針

 int i;

 L[MAXSIZE-1].cur=0;

 for (i=0;iMAXSIZE-2;i++)

  L[i].cur=i+1;

 L[MAXSIZE-2].cur=0;

 return OK;

}

Status ClearList(SLinkList L)

 //初始條件:線性表L已存在。操作結果:將L重置為空表

 int i,j,k;

 i=L[MAXSIZE-1].cur;

 L[MAXSIZE-1].cur=0;

 k=L[0].cur;

 L[0].cur=i;

 while (i)

 {

  j=i;

  i=L[i].cur;

 }

 L[j].cur=k;

 return OK;

}

BOOL ListEmpty(SLinkList L)

 //若L是空表,返回TRUE;否則返回FALSE

 if (!L[MAXSIZE-1].cur)

  return TRUE;

 else

  return FALSE;

}

int ListLength(SLinkList L)

 //返回L中數據元素個數

 int i,len;

 i=L[MAXSIZE-1].cur;

 len=0;

 while (i)

 {

  i=L[i].cur;

  len++;

 }

 return len;

}

Status GetElem(SLinkList L,int i,LElemType *e)

 //用e返回L中第i個元素的值

 int j,k=MAXSIZE-1;

 if (i1||iListLength(L))

  return ERROR;

 for (j=1;j=i;j++)

  k=L[k].cur;

 *e=L[k].data;

 return OK;

}

int LocateElem(SLinkList L,LElemType e) 

 //在靜態單鏈線性表L中查找第1個值為e的元素。若找到,則返回它在L中的

 //位序,否則返回0。(與其它LocateElem()的定義不同)

 int i=L[MAXSIZE-1].cur;

 while (iL[i].data!=e)

  i=L[i].cur;

 return i;

}

Status PriorElem(SLinkList L,LElemType cur_e,LElemType *pre_e)

 //初始條件:線性表L已存在

 //操作結果:若cur_e是L的數據元素,且不是第一個,則用pre_e返回它的前驅,

 //          否則操作失敗,pre_e無定義

 int i,j;

 i=L[MAXSIZE-1].cur; 

 do{

  j=i;

  i=L[i].cur;

 }while (iL[i].data!=cur_e);

 if (i)

 {

  *pre_e=L[j].data;

  return OK;

 }

 return ERROR;

}

Status NextElem(SLinkList L,LElemType cur_e,LElemType *next_e)

 //初始條件:線性表L已存在

 //操作結果:若cur_e是L的數據元素,且不是最後一個,則用next_e返回它的後繼,

 //          否則操作失敗,next_e無定義

 int i,j;

 i=LocateElem(L,cur_e);

 if (i)

 {

  j=L[i].cur;

  if (j)

  {

   *next_e=L[j].data;

   return OK;

  }

 }

 return ERROR;

}

Status ListInsert(SLinkList L,int i,LElemType e)

 //在L中第i個元素之前插入新的數據元素e

 int j,k,l;

 k=MAXSIZE-1;

 if (i1||iListLength(L)+1)

  return ERROR;

 j=Malloc(L);

 if (j)

 {

  L[j].data=e;

  for(l=1;l=i-1;l++)

   k=L[k].cur;

  L[j].cur=L[k].cur;

  L[k].cur=j;

  return OK;

 }

 return ERROR;

}

Status ListDelete(SLinkList L,int i,LElemType *e)

{

 //刪除在L中第i個數據元素e,並返回其值

 int j,k;

 if (i1||iListLength(L))

  return ERROR;

 k=MAXSIZE-1;

 for (j=1;j=i-1;j++)

  k=L[k].cur;

 j=L[k].cur;

 L[k].cur=L[j].cur;

 *e=L[j].data;

 Free(L,j);

 return OK;

}

Status ListTraverse(SLinkList L,void (* visit)(LElemType e))

 int i=L[MAXSIZE-1].cur;

 while (i)

 {

  visit(L[i].data);

  i=L[i].cur;

 }

 return OK;

}

void Visit(LElemType e)

{

 printf(“%d\n”,e);

}

int main()

{

 int i,j,k;

 LElemType e,e0;

 SLinkList L;

 InitList(L);

 for(j=1;j=5;j++)

  i=ListInsert(L,1,j);

 ListTraverse(L,Visit);

 //判斷鏈表是否為空

 i=ListEmpty(L);

 printf(“%d\n”,i);

 //打印鏈表長度

 printf(“%d\n”,ListLength(L));

 //清空靜態鏈表

 ClearList(L);

 ListTraverse(L,Visit);

 for(j=1;j=10;j++)

  ListInsert(L,j,j);

 //插入新節點後

 ListTraverse(L,Visit);

 //獲取鏈表中的第5個元素

 GetElem(L,5,e);

 printf(“%d\n”,e);

 for(j=0;j=1;j++)

 {

  k=LocateElem(L,j);

  if(k)

   printf(“%d %d\n”,j,k);//j在鏈表中的序號k

  else

   printf(“Can’t find %d\n”,j);//鏈表中不存在j

 }

 for(j=1;j=2;j++) //測試頭兩個數據

 {

  GetElem(L,j,e0); //把第j個數據賦給e0

  i=PriorElem(L,e0,e); //求e0的前驅

  if(!i)

   printf(“No elem before %d\n”,e0);

  else

   printf(“Elem before %d is %d\n”,e0,e);//數據e0的前驅

 }

 for(j=ListLength(L)-1;j=ListLength(L);j++) //最後兩個數據

 {

  GetElem(L,j,e0); //把第j個數據賦給e0

  i=NextElem(L,e0,e); //求e0的後繼

  if(!i)

   printf(“No elem after %d\n”,e0);

  else

   printf(“The elem after % is %d\n”,e0,e);//數據e0的後繼

 }

 k=ListLength(L); //k為表長

 for(j=k+1;j=k;j–)

 {

  i=ListDelete(L,j,e); //刪除第j個數據

  if(i)

   printf(“Delete Succussfully\n”);

  else

   printf(“Can’t find the elem\n”,j);

 }

 ListTraverse(L,Visit);

 return 0;

}

給你找了個靜態鏈表的代碼,能編譯運行

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/155294.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-17 02:39
下一篇 2024-11-17 02:39

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python字符串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字符串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字符串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變量和數…

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在着手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29
  • 怎麼寫不影響Python運行的長段代碼

    在Python編程的過程中,我們不可避免地需要編寫一些長段代碼,包括函數、類、複雜的控制語句等等。在編寫這些代碼時,我們需要考慮代碼可讀性、易用性以及對Python運行性能的影響。…

    編程 2025-04-29

發表回復

登錄後才能評論