虫虫首页| 资源下载| 资源专辑| 精品软件
登录| 注册

null

  • 两个链表的交集

    两个链表的交集 #include<stdio.h> #include<stdlib.h> typedef struct Node{   int data;   struct  Node *next; }Node; void initpointer(struct Node *p){   p=null; } int  printlist(struct Node* head){   int flag=1;   head=head->next;   /*   因为标记1的地方你用了头结点,所以第一个数据域无效,应该从下一个头元结点开始   */   if(head==null)     printf("null\n");   else   {     while(head!=null)     {       if(flag==1)       {       printf("%d",head->data);       flag=0;       }       else       {         printf(" %d",head->data);       }       head=head->next;     }     printf("\n");   }   return 0; } struct Node *creatlist(struct Node *head) {      int n;    struct  Node *p1=(struct Node *)malloc(sizeof(struct Node));   p1->next=null; while(scanf("%d",&n),n!=-1) {   struct Node *pnode=(struct Node *)malloc(sizeof(struct Node));   pnode->next=null;      pnode->data=n;   if(head==null)     head=pnode;   p1->next=pnode;   p1=pnode; } return head; } struct Node *Intersect(struct Node *head1, struct Node *head2) { struct Node *p1=head1,*p2=head2;/*我这里没有用头指针和头结点,这里是首元结点head1里面就是第一个数据,一定要理解什么事头指针, 头结点,和首元结点 具体你一定要看这个博客:http://blog.sina.com.cn/s/blog_71e7e6fb0101lipz.html*/ struct Node *head,*p,*q; head = (struct Node *)malloc(sizeof(struct Node)); head->next = null; p = head; while( (p1!=null)&&(p2!=null) ) { if (p1->data == p2->data) { q = (struct Node *)malloc(sizeof(struct Node)); q->data = p1->data; q->next = null; p->next = q;//我可以认为你这里用了头结点,也就是说第一个数据域无效     **标记1** p = q; p1 = p1->next; p2 = p2->next; } else if (p1->data < p2->data) { p1 = p1->next; } else { p2 = p2->next; } } return head; } int main() {   struct Node *head=null,*headt=null,*t;   //initpointer(head);//这里的函数相当于head=null;  // initpointer(headt);//上面已经写了headt=null那么这里可以不用调用这个函数   head=creatlist(head);   headt=creatlist(headt);   t=Intersect(head,headt);   printlist(t); }

    标签: c语言编程

    上传时间: 2015-04-27

    上传用户:coco2017co

  • asp实现限制一个ip只能访问一次的方法

    asp实现限制一个ip只能访问一次的方法 <%  '/////////////////////////////////////////////////////  '// //  '//作用:一个IP地址只允许访问本页一次 //  '//引用:<!-- #include file="Check_Ip.asp" --> //  '// //  '/////////////////////////////////////////////////////    'Response.Charset = 936 '设置输出编码为简体中文  'Response.Buffer = false '关闭缓冲区    Dim Fso,ts,IpList,Cfs    '设置Cookies函数  Function SetCookie()  Response.Cookies("IsBrow") = "Brow" Response.Cookies("IsBrow").Expires = Date+365  End Function    '记录IP地址函数  Function WriteIp(FileName, IpAddress)  Set Fso = Server.CreateObject("Scripting.FileSystemObject")  Set ts = Fso.OpenTextFile(Server.MapPath(FileName),8,true)  ts.WriteLine IpAddress  ts.Close  Set ts = Nothing  Set Fso = Nothing  End Function    '读取IP地址函数  Function ReadIpList(FileName)  Set Fso = Server.CreateObject("Scripting.FileSystemObject")  If Not Fso.FileExists(Server.MapPath(FileName)) Then  CreateFile("Iplist.txt")  Exit Function  End If    Set ts = Fso.OpenTextFile(Server.MapPath(FileName))  Iplist = ts.ReadAll  ts.Close  Set ts = Nothing  Set Fso = Nothing  ReadIpList = Iplist  End Function    '创建文件函数  Function CreateFile(FileName)  Set Fso = Server.CreateObject("Scripting.FileSystemObject")  Set Cfs = Fso.CreateTextFile(Server.MapPath(FileName))  Cfs.Close  Set Cfs = Nothing  Set Fso = Nothing  End Function    '关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)  Function CloseWindow()  'Response.Write "<script>window.location='javascript:window.opener=null;window.close();'</script>"  Response.Redirect "http://www.baidu.com" End Function    Ip = Request.ServerVariables("REMOTE_ADDR") '获取浏览者IP地址    Cookie = Request.Cookies("IsBrow") '获取当前Cookies  'Response.Write Cookie    If Request.ServerVariables("HTTP_X_FORWARDED_FOR") <> "" Then  Response.Write "本站不允许使用代理访问" Response.End()  Else  If Cookie = "Brow" Then  CloseWindow()  Else  If Instr(ReadIpList("Iplist.txt"),Ip) <>0  Then  CloseWindow()  Else  WriteIp "Iplist.txt" , Ip  End If  SetCookie()  End If  End If  %>

    标签: asp 访问

    上传时间: 2016-07-14

    上传用户:helei0915

  • 运动会源代码

    #include <malloc.h>       #include <stdio.h>       #include <stdlib.h>       #include <string.h>       #define null 0      #define MaxSize 30          typedef struct athletestruct /*运动员*/     {         char name[20];          int score; /*分数*/         int range; /**/         int item; /*项目*/     }ATH;     typedef struct schoolstruct /*学校*/     {         int count; /*编号*/         int serial; /**/          int menscore; /*男选手分数*/         int womenscore; /*女选手分数*/         int totalscore; /*总分*/         ATH athlete[MaxSize]; /**/         struct schoolstruct *next;      }SCH;         int nsc,msp,wsp;      int ntsp;      int i,j;      int overgame;      int serial,range;      int n;      SCH *head,*pfirst,*psecond;      int *phead=null,*pafirst=null,*pasecond=null;     void create();         void input ()     {         char answer;          head = (SCH *)malloc(sizeof(SCH)); /**/         head->next = null;         pfirst = head;          answer = 'y';         while ( answer == 'y' )         {         Is_Game_DoMain:         printf("\nGET Top 5 when odd\nGET Top 3 when even");         printf("\n输入运动项目序号 (x<=%d):",ntsp);         scanf("%d",pafirst);         overgame = *pafirst;         if ( pafirst != phead )         {             for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )             {                 if ( overgame == *pasecond )                 {                     printf("\n这个项目已经存在请选择其他的数字\n");                     goto Is_Game_DoMain;                 }             }         }         pafirst = pafirst + 1;         if ( overgame > ntsp )         {             printf("\n项目不存在");             printf("\n请重新输入");             goto Is_Game_DoMain;         }         switch ( overgame%2 )         {         case 0: n = 3;break;         case 1: n = 5;break;         }         for ( i = 1 ; i <= n ; i++ )         {         Is_Serial_DoMain:         printf("\n输入序号 of the NO.%d (0<x<=%d): ",i,nsc);                 scanf("%d",&serial);         if ( serial > nsc )          {             printf("\n超过学校数目,请重新输入");             goto Is_Serial_DoMain;         }         if ( head->next == null )          {             create();         }         psecond = head->next ;          while ( psecond != null )          {             if ( psecond->serial == serial )             {                 pfirst = psecond;                 pfirst->count = pfirst->count + 1;                 goto Store_Data;             }             else             {                 psecond = psecond->next;             }         }         create();         Store_Data:                 pfirst->athlete[pfirst->count].item = overgame;         pfirst->athlete[pfirst->count].range = i;         pfirst->serial = serial;         printf("Input name:) : ");                 scanf("%s",pfirst->athlete[pfirst->count].name);         }         printf("\n继续输入运动项目(y&n)?");         answer = getchar();         printf("\n");         }     }         void calculate() /**/     {         pfirst = head->next;         while ( pfirst->next != null )         {             for (i=1;i<=pfirst->count;i++)             {                 if ( pfirst->athlete[i].item % 2 == 0 )                  {                     switch (pfirst->athlete[i].range)                     {                     case 1:pfirst->athlete[i].score = 5;break;                     case 2:pfirst->athlete[i].score = 3;break;                     case 3:pfirst->athlete[i].score = 2;break;                     }                 }                 else                  {                     switch (pfirst->athlete[i].range)                     {                     case 1:pfirst->athlete[i].score = 7;break;                     case 2:pfirst->athlete[i].score = 5;break;                     case 3:pfirst->athlete[i].score = 3;break;                     case 4:pfirst->athlete[i].score = 2;break;                     case 5:pfirst->athlete[i].score = 1;break;                     }                 }                 if ( pfirst->athlete[i].item <=msp )                  {                     pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;                 }                 else                  {                     pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;                 }             }             pfirst->totalscore = pfirst->menscore + pfirst->womenscore;             pfirst = pfirst->next;         }     }         void output()     {         pfirst = head->next;         psecond = head->next;         while ( pfirst->next != null )          {             // clrscr();              printf("\n第%d号学校的结果成绩:",pfirst->serial);             printf("\n\n项目的数目\t学校的名字\t分数");             for (i=1;i<=ntsp;i++)              {                 for (j=1;j<=pfirst->count;j++)                  {                     if ( pfirst->athlete[j].item == i )                     {                                                                         printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;                                             }                 }             }             printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");             getchar();             pfirst = pfirst->next;         }     //  clrscr();          printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");         pfirst = head->next;         while ( pfirst->next != null )         {             printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);             pfirst = pfirst->next;         }         printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");         getchar();     }         void create()     {                 pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));         pfirst->next = head->next ;         head->next = pfirst ;                 pfirst->count = 1;         pfirst->menscore = 0;         pfirst->womenscore = 0;         pfirst->totalscore = 0;     }     void Save()     {FILE *fp;     if((fp = fopen("school.dat","wb"))==null)     {printf("can't open school.dat\n");     fclose(fp);     return;     }     fwrite(pfirst,sizeof(SCH),10,fp);     fclose(fp);     printf("文件已经成功保存\n");     }         void main()     {         system("cls");         printf("\n\t\t\t 运动会分数统计\n");         printf("输入学校数目 (x>= 5):");         scanf("%d",&nsc);          printf("输入男选手的项目(x<=20):");         scanf("%d",&msp);          printf("输入女选手项目(<=20):");         scanf("%d",&wsp);          ntsp = msp + wsp;                  phead = (int *)calloc(ntsp,sizeof(int));         pafirst = phead;         pasecond = phead;         input();         calculate();          output();         Save();     }             

    标签: 源代码

    上传时间: 2016-12-28

    上传用户:150501

  • 学生成绩查询

    #include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp; int time=0,i=0,j=0,add[80],k=0,m; char *ch, str[900]; m=strlen(pd); if((fp=fopen("haha.txt","r"))==null) { printf("Cannot open this file\n"); exit(0); } for(;!feof(fp);i++) { str[i]=fgetc(fp); if(tolower(str[i])==tolower(pd[k])) {k++; if(k==m) if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp)))) { time++; add[j]=i-m+1; j++; k=0; } else k=0; } } if(time) { printf("The time is:%d\n",time); printf("The adders is:\n"); for(i=0;i

    标签: 查询学会少年宫

    上传时间: 2016-12-29

    上传用户:767483511

  • 学生成绩管理啊

    #include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp;  int time=0,i=0,j=0,add[80],k=0,m;  char *ch,  str[900];  m=strlen(pd);  if((fp=fopen("haha.txt","r"))==null)  {   printf("Cannot open this file\n");   exit(0);  } for(;!feof(fp);i++)  {  str[i]=fgetc(fp);   if(tolower(str[i])==tolower(pd[k]))    {k++;     if(k==m)     if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp))))     {      time++;      add[j]=i-m+1;      j++;      k=0;     }     else k=0;   }  }   if(time)  {   printf("The time is:%d\n",time);   printf("The adders is:\n");   for(i=0;i<j;i++)   printf("%5d",add[i]);   if(i%5==0)   printf("\n");   getch();   fclose(fp);   }   else   printf("Sorry!Cannot find the word(^_^)"); } main() { char pd[10],choose='y'; int flag=1;     while(flag)    {printf("In put the word you want to seqarch:");     scanf("%s",pd);     search(strlwr(pd));     printf("\nWould you want to continue?(Y/N):");     getchar();     scanf("%c",&choose);     if((tolower(choose))=='n')     flag=0;     else flag=1;    }   printf("Thanks for your using!Bye-bye!\n");   getch(); }

    标签: 学生专用

    上传时间: 2016-12-29

    上传用户:767483511

  • c#简单计算器

    // 学生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person {   char name[10];   int ID;   int cj_yw;   int cj_sx;   struct person* next;   struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance,                      HINSTANCE hPrevInstance,                      LPSTR     lpCmdLine,                      int       nCmdShow) {   // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow))  { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, null, 0, 0))  { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))  { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // //  FUNCTION: MyRegisterClass() // //  PURPOSE: Registers the window class. // //  COMMENTS: // //    This function and its usage is only necessary if you want this code //    to be compatible with Win32 systems prior to the 'RegisterClassEx' //    function that was added to Windows 95. It is important to call this function //    so that the application will get 'well formed' small icons associated //    with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(null, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // //   FUNCTION: InitInstance(HANDLE, int) // //   PURPOSE: Saves instance handle and creates main window // //   COMMENTS: // //        In this function, we save the instance handle in a global variable and //        create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hWnd;    hInst = hInstance; // Store instance handle in our global variable    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, null, null, hInstance, null);    if (!hWnd)    {       return FALSE;    }    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    return TRUE; } // //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // //  PURPOSE:  Processes messages for the main window. // //  WM_COMMAND - process the application menu //  WM_PAINT - Paint the main window //  WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)  { case WM_COMMAND: wmId    = LOWORD(wParam);  wmEvent = HIWORD(wParam);  // Parse the menu selections: switch (wmId) { case IDM_ABOUT:   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);   break; case IDM_EXIT:   DestroyWindow(hWnd);   break; default:   return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam);    }    return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)  { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; }     return FALSE; }

    标签: 计算器 学生

    上传时间: 2016-12-29

    上传用户:767483511

  • 简单的计算器

    // 学生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person {   char name[10];   int ID;   int cj_yw;   int cj_sx;   struct person* next;   struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance,                      HINSTANCE hPrevInstance,                      LPSTR     lpCmdLine,                      int       nCmdShow) {   // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow))  { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, null, 0, 0))  { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))  { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // //  FUNCTION: MyRegisterClass() // //  PURPOSE: Registers the window class. // //  COMMENTS: // //    This function and its usage is only necessary if you want this code //    to be compatible with Win32 systems prior to the 'RegisterClassEx' //    function that was added to Windows 95. It is important to call this function //    so that the application will get 'well formed' small icons associated //    with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(null, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // //   FUNCTION: InitInstance(HANDLE, int) // //   PURPOSE: Saves instance handle and creates main window // //   COMMENTS: // //        In this function, we save the instance handle in a global variable and //        create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hWnd;    hInst = hInstance; // Store instance handle in our global variable    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, null, null, hInstance, null);    if (!hWnd)    {       return FALSE;    }    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    return TRUE; } // //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // //  PURPOSE:  Processes messages for the main window. // //  WM_COMMAND - process the application menu //  WM_PAINT - Paint the main window //  WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)  { case WM_COMMAND: wmId    = LOWORD(wParam);  wmEvent = HIWORD(wParam);  // Parse the menu selections: switch (wmId) { case IDM_ABOUT:   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);   break; case IDM_EXIT:   DestroyWindow(hWnd);   break; default:   return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam);    }    return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)  { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; }     return FALSE; }

    标签: 学生 计算器

    上传时间: 2016-12-29

    上传用户:767483511

  • 数据结构实验

    #include <stdio.h>   #include <stdlib.h> ///链式栈      typedef struct node   {       int data;       struct node *next;   }Node,*Linklist;      Linklist Createlist()   {       Linklist p;       Linklist h;       int data1;       scanf("%d",&data1);       if(data1 != 0)       {           h = (Node *)malloc(sizeof(Node));           h->data = data1;           h->next = null;       }       else if(data1 == 0)       return null;       scanf("%d",&data1);       while(data1 != 0)       {           p = (Node *)malloc(sizeof(Node));           p -> data = data1;           p -> next = h;           h = p;           scanf("%d",&data1);       }       return h;   }      void Outputlist(Node *head)   {       Linklist p;       p = head;       while(p != null )       {           printf("%d ",p->data);           p = p->next;       }       printf("\n");   }      void Freelist(Node *head)   {       Node *p;       Node *q = null;       p = head;       while(p != null)       {           q = p;           p = p->next;           free(q);       }   }      int main()   {       Node *head;       head = Createlist();          Outputlist(head);          Freelist(head);          return 0;   }   2.顺序栈 [cpp] view plain copy #include <iostream>   #include <stdio.h>   #include <stdlib.h> ///顺序栈   #define MaxSize 100      using namespace std;      typedef

    标签: 数据结构 实验

    上传时间: 2018-05-09

    上传用户:123456..

  • 数据结构实验

    #include <iostream> #include <stdio.head> #include <stdlib.head> #include <string.head> #define ElemType int #define max 100 using namespace std; typedef struct node1 { ElemType data; struct node1 *next; }Node1,*LinkList;//链栈 typedef struct { ElemType *base; int top; }SqStack;//顺序栈 typedef struct node2 { ElemType data; struct node2 *next; }Node2,*LinkQueue; typedef struct node22 { LinkQueue front; LinkQueue rear; }*LinkList;//链队列 typedef struct { ElemType *base; int front,rear; }SqQueue;//顺序队列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 //1.采用链式存储实现栈的初始化、入栈、出栈操作。 LinkList CreateStack()//创建栈 { LinkList top; top=null; return top; } bool StackEmpty(LinkList s)//判断栈是否为空,0代表空 { if(s==null) return 0; else return 1; } LinkList Pushead(LinkList s,int x)//入栈 { LinkList q,top=s; q=(LinkList)malloc(sizeof(Node1)); q->data=x; q->next=top; top=q; return top; } LinkList Pop(LinkList s,int &e)//出栈 { if(!StackEmpty(s)) { printf("栈为空。"); } else { e=s->data; LinkList p=s; s=s->next; free(p); } return s; } void DisplayStack(LinkList s)//遍历输出栈中元素 { if(!StackEmpty(s)) printf("栈为空。"); else { wheadile(s!=null) { cout<<s->data<<" "; s=s->next; } cout<<endl; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //2.采用顺序存储实现栈的初始化、入栈、出栈操作。 int StackEmpty(int t)//判断栈S是否为空 { SqStack.top=t; if (SqStack.top==0) return 0; else return 1; } int InitStack() { SqStack.top=0; return SqStack.top; } int pushead(int t,int e) { SqStack.top=t; SqStack.base[++SqStack.top]=e; return SqStack.top; } int pop(int t,int *e)//出栈 { SqStack.top=t; if(!StackEmpty(SqStack.top)) { printf("栈为空."); return SqStack.top; } *e=SqStack.base[s.top]; SqStack.top--; return SqStack.top; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //3.采用链式存储实现队列的初始化、入队、出队操作。 LinkList InitQueue()//创建 { LinkList head; head->rear=(LinkQueue)malloc(sizeof(Node)); head->front=head->rear; head->front->next=null; return head; } void deleteEle(LinkList head,int &e)//出队 { LinkQueue p; p=head->front->next; e=p->data; head->front->next=p->next; if(head->rear==p) head->rear=head->front; free(p); } void EnQueue(LinkList head,int e)//入队 { LinkQueue p=(LinkQueue)malloc(sizeof(Node)); p->data=e; p->next=null; head->rear->next=p; head->rear=p; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //4.采用顺序存储实现循环队列的初始化、入队、出队操作。 bool InitQueue(SqQueue &head)//创建队列 { head.data=(int *)malloc(sizeof(int)); head.front=head.rear=0; return 1; } bool EnQueue(SqQueue &head,int e)//入队 { if((head.rear+1)%MAXQSIZE==head.front) { printf("队列已满\n"); return 0; } head.data[head.rear]=e; head.rear=(head.rear+1)%MAXQSIZE; return 1; } int QueueLengthead(SqQueue &head)//返回队列长度 { return (head.rear-head.front+MAXQSIZE)%MAXQSIZE; } bool deleteEle(SqQueue &head,int &e)//出队 { if(head.front==head.rear) { cout<<"队列为空!"<<endl; return 0; } e=head.data[head.front]; head.front=(head.front+1)%MAXQSIZE; return 1; } int gethead(SqQueue head)//得到队列头元素 { return head.data[head.front]; } int QueueEmpty(SqQueue head)//判断队列是否为空 { if (head.front==head.rear) return 1; else return 0; } void travelQueue(SqQueue head)//遍历输出 { wheadile(head.front!=head.rear) { printf("%d ",head.data[head.front]); head.front=(head.front+1)%MAXQSIZE; } cout<<endl; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 //5.在主函数中设计一个简单的菜单,分别测试上述算法。 int main() { LinkList top=CreateStack(); int x; wheadile(scanf("%d",&x)!=-1) { top=Pushead(top,x); } int e; wheadile(StackEmpty(top)) { top=Pop(top,e); printf("%d ",e); }//以上是链栈的测试 int top=InitStack(); int x; wheadile(cin>>x) top=pushead(top,x); int e; wheadile(StackEmpty(top)) { top=pop(top,&e); printf("%d ",e); }//以上是顺序栈的测试 LinkList Q; Q=InitQueue(); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q,x); } int e; wheadile(Q) { deleteEle(Q,e); printf("%d ",e); }//以上是链队列的测试 SqQueue Q1; InitQueue(Q1); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q1,x); } int e; wheadile(QueueEmpty(Q1)) { deleteEle(Q1,e); printf("%d ",e); } return 0; }

    标签: 数据结构 实验

    上传时间: 2018-05-09

    上传用户:123456..

  • 成绩查询系统

    #include<stdio.h> #include<string.h> #include<stdlib.h> #define N 100 int iNumOfStu=0; struct score   {   float math;   float english;   float computer;   }; struct student   {   int number;   char name[20];   struct score sco;   float average;   }; struct student stu[N]; void print_menu(void);//输出菜单 void choosemenu(void);//菜单选择 void input_student1(int);//输入学生信息 void input_student2(void);//输入总函数 void input_student3(int &,int);//判断学号是否重复 void input_student4(int,int);//覆盖原信息 void sort_student3(student s[],int);//按照英语成绩排序 void sort_student4(student s[],int);//按照计算机成绩排序 void sort_student2(student s[],int);//按照数学成绩排序 void sort_student5(student s[],int);//按照平均成绩排序 float input_score2(int);//计算学生平均成绩 void print_student2(void);//显示表头 void print_student3(int);//显示学生信息 void print_student1(int);//显示全部学生资料 void sort_student1(void);//排序总函数 void menu(void);//菜单调度总函数 int search_student2(int);//按学号查询学生信息并输出 void search_student3(int);//按平均分最高查询并输出 void search_student1(void);//查询总函数 void delete_student2(int,int);//删除学生信息 void delete_student1(void);//删除总函数 void change_student2(int);//修改学生资料 void change_student1(void);//修改总函数 void input_score3(int);//统计成绩 void input_score1(void);//统计成绩总函数 void print_help(void);//输出帮助信息 void exit_student(void);//退出系统 void save_student(student *,int);//保存学生信息 void main()   {   menu();   } void save_student(student *s,int a)//保存学生信息   {   FILE *fp;     if((fp=fopen("d:\\学生信息.txt","wb"))==null)       {       printf("不能打开文件!\n");       }     else       {       printf("保存信息到D盘\n");       fprintf(fp,"本班所有学生具体信息如下:\r\n");       fprintf(fp,"  学号       姓名           数学成绩       英语成绩     计算机成绩     平均成绩\r\n");       for(int i=0;i<a;i++)         {         fprintf(fp,"%8d%12s%14.2f%14.2f%14.2f%14.2f\n",stu[i].number,stu[i].name,stu[i].sco.math,stu[i].sco.english,stu[i].sco.computer,stu[i].average);         fprintf(fp,"\r\n");         }       fclose(fp);       printf("信息保存成功!\n");       }   } void exit_student(void)//退出系统   {   exit(1);   } void print_help(void)//输出帮助信息   {   printf("本系统所能容纳的最大学生数为%d人\n学生信息保存在D盘根目录下,保存文件为“学生信息.txt”。\n感谢使用!\n",N);   } void input_score1(void)//统计成绩总函数   {   int c;   c=search_student2(iNumOfStu);   printf("学号:%d\n",stu[c].number);   printf("姓名:%s\n",stu[c].name);   input_score3(c);   printf("新成绩录入成功!\n");   stu[c].average=input_score2(c);   } void input_score3(int a)//统计成绩   {   printf("数学新成绩:");   scanf("%f",&stu[a].sco.math);   printf("英语新成绩:");   scanf("%f",&stu[a].sco.english);   printf("计算机新成绩:");   scanf("%f",&stu[a].sco.computer);   } void change_student2(int a)//修改学生资料   {   printf("学号:%d----修改为:",stu[a].number);   scanf("%d",&stu[a].number);   getchar();   printf("姓名:%s----修改为:",stu[a].name);   gets(stu[a].name);   printf("数学成绩:%.2f----修改为:",stu[a].sco.math);   scanf("%f",&stu[a].sco.math);   printf("英语成绩:%.2f----修改为:",stu[a].sco.english);   scanf("%f",&stu[a].sco.english);   printf("计算机成绩:%.2f----修改为:",stu[a].sco.computer);   scanf("%f",&stu[a].sco.computer);   } void change_student1(void)//修改总函数   {   int c;   c=search_student2(iNumOfStu);   getchar();   printf("是否要修改此学生信息?(“y”代表是)");   char d;   scanf("%c",&d);   if(d=='y'||d=='Y')     {     change_student2(c);       stu[c].average=input_score2(c);     printf("信息修改成功!\n");     }   } void delete_student1(void)//删除总函数   {   int c;   c=search_student2(iNumOfStu);   getchar();   printf("是否删除此条记录?(“y”代表是)");   char d;   scanf("%c",&d);   if(d=='y'||d=='Y')     {     delete_student2(c,iNumOfStu);     printf("记录已删除!\n");     }   } void delete_student2(int a,int b)//删除学生信息   {   for(int i=a;i<b-1;i++)     {     stu[i]=stu[i+1];     }   --iNumOfStu;   } void search_student1(void)//查询总函数   {   printf("1、按学号查询\n2、按平均分最高查询\n请选择:");   int c;   scanf("%d",&c);   switch(c)     {     case 1:       {       search_student2(iNumOfStu);       break;       }     case 2:       {       search_student3(iNumOfStu);       break;       }     default: break;     }   } void menu(void)//菜单调度总函数   {   print_menu();   choosemenu();   } void sort_student1(void)//排序总函数   {   printf("1、按数学成绩排序\n2、按英语成绩排序\n3、按计算机成绩排序\n4、按平均成绩排序\n请选择:");   int c;   scanf("%d",&c);   switch(c)     {     case 1:       {       sort_student2(stu,iNumOfStu);       break;       }     case 2:       {       sort_student3(stu,iNumOfStu);       break;       }     case 3:       {       sort_student4(stu,iNumOfStu);       break;       }     case 4:       {       sort_student5(stu,iNumOfStu);       break;       }     default: break;     }   } void print_student1(int a)//显示全部学生资料   {   printf("本班所有学生具体信息如下\n");   print_student2();   for(int i=0;i<a;i++)     {     print_student3(i);     }   } void print_student3(int a)//显示学生信息   {   printf("%8d%12s%14.2f%14.2f%14.2f%14.2f\n",stu[a].number,stu[a].name,stu[a].sco.math,stu[a].sco.english,stu[a].sco.computer,stu[a].average);   } void print_student2(void)//显示表头   {   printf("  学号       姓名           数学成绩       英语成绩     计算机成绩     平均成绩\n");   } void input_student4(int a,int b)//覆盖原信息   {   stu[a]=stu[b-1];   --iNumOfStu;   } void input_student3(int &a,int b)//判断学号是否重复   {   if(a!=0)     {     int i=0;     do       {       if(stu[a].number==stu[i].number)         {         printf("此学号代表的学生已录入\n1、覆盖原信息\n2、重新输入\n请选择:");         int c;         scanf("%d",&c);         switch(c)           {           case 1:             {             input_student4(i,iNumOfStu);             a=iNumOfStu-1;             printf("信息已替换!\n");             break;             }           case 2:             {             printf("请重新输入学生信息:\n");             input_student1(iNumOfStu-1);             break;             }           default: break;           }         break;         }       ++i;       }       while(i<b-1);     }   } void print_menu(void)//输出菜单   {   printf("======欢迎来到学生信息管理系统======\n");   printf("      1、输入学生资料\n");   printf("      2、删除学生资料\n");   printf("      3、查询学生资料\n");   printf("      4、修改学生资料\n");   printf("      5、显示学生资料\n");   printf("      6、统计学生成绩\n");   printf("      7、排序学生成绩\n");   printf("      8、保存学生资料\n");   printf("      9、获取帮助信息\n");   printf("      10、退出系统\n");   printf("====================================\n");   printf("请选择:");   } void input_student2(void)//输入总函数   {   char end;   printf("请输入学生信息(在最后一个学生信息录入完成后以“/”结束录入):\n");   for(int i=0;(end=getchar())!='/';i++)     {     input_student1(i);     ++iNumOfStu;     input_student3(i,iNumOfStu);     }   for(int j=0;j<iNumOfStu;j++)     {     stu[j].average=input_score2(j);     }   } void input_student1(int a)//输入学生信息   {   printf("学号:");   scanf("%d",&stu[a].number);   getchar();   printf("姓名:");   gets(stu[a].name);   printf("数学成绩:");   scanf("%f",&stu[a].sco.math);   printf("英语成绩:");   scanf("%f",&stu[a].sco.english);   printf("计算机成绩:");   scanf("%f",&stu[a].sco.computer);   } float input_score2(int a)//计算学生平均成绩   {   return (stu[a].sco.math+stu[a].sco.english+stu[a].sco.computer)/3;   } void search_student3(int a)//按平均分最高查询并输出   {   int max=0;   for(int i=0;i<a;i++)     {     if(stu[max].average<stu[i].average)       {       max=i;       }     }   print_student2();   print_student3(max);   } void sort_student2(student s[],int a)//按照数学成绩排序   {   struct student temp;   for(int i=0;i<a-1;i++)     {     int max=i;     for(int j=i+1;j<a;j++)       if(stu[j].sco.math>stu[max].sco.math)         {         max=j;         }     if(max!=i)       {       temp=stu[max];       stu[max]=stu[i];       stu[i]=temp;       }     }   print_student2();   for(int k=0;k<a;k++)     {     print_student3(k);     }   } void sort_student3(student s[],int a)//按照英语成绩排序   {   struct student temp;   for(int i=0;i<a-1;i++)     {     int max=i;     for(int j=i+1;j<a;j++)       if(stu[j].sco.english>stu[max].sco.english)         {         max=j;         }     if(max!=i)       {       temp=stu[max];       stu[max]=stu[i];       stu[i]=temp;       }     }   print_student2();   for(int k=0;k<a;k++)     {     print_student3(k);     }   } void sort_student4(student s[],int a)//按照计算机成绩排序   {   struct student temp;   for(int i=0;i<a-1;i++)     {     int max=i;     for(int j=i+1;j<a;j++)       if(stu[j].sco.computer>stu[max].sco.computer)         {         max=j;         }     if(max!=i)       {       temp=stu[max];       stu[max]=stu[i];       stu[i]=temp;       }     }   print_student2();   for(int k=0;k<a;k++)     {     print_student3(k);     }   } void sort_student5(student s[],int a)//按照平均成绩排序   {   struct student temp;   for(int i=0;i<a-1;i++)     {     int max=i;     for(int j=i+1;j<a;j++)       if(stu[j].average>stu[max].average)         {         max=j;         }     if(max!=i)       {       temp=stu[max];       stu[max]=stu[i];       stu[i]=temp;       }     }   print_student2();   for(int k=0;k<a;k++)     {     print_student3(k);     }   } int search_student2(int a)//按照学号查找学生并输出   {   int num;   int c;   printf("请输入要查询的学号:");   scanf("%d",&num);   for(int i=0;i<a;i++)     {     if(num==stu[i].number)       {       c=i;       }     }   printf("此学生的信息是:\n");   print_student2();   print_student3(c);   return c;   } void choosemenu(void)//菜单选择   {   int i;   scanf("%d",&i);   switch(i)     {     case 1:       {       input_student2();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 2:       {       delete_student1();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 3:       {       search_student1();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 4:       {       change_student1();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 5:       {       print_student1(iNumOfStu);       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 6:       {       input_score1();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 7:       {       sort_student1();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 8:       {       save_student(stu,iNumOfStu);       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 9:       {       print_help();       printf("按回车键返回主菜单");       getchar();       getchar();       menu();       break;       }     case 10:       {       exit_student();       }     default: break;     }   }         运行结果:                         源文件下载地址: http://115.com/file/clnq138g#一个简单的学生成绩管理系统.rar (请将此地址复制到浏览器地址栏中访问下载页面)  

    标签: 成绩查询系统

    上传时间: 2019-06-08

    上传用户:啊的撒旦