#include<iostream>
#include<string.h>
#include<malloc.h> /* malloc()μè */
#include<stdio.h> /* EOF(=^Z?òF6),NULL */
#include<stdlib.h> /* atoi() */
#include<math.h>
using namespace std;
#define ERROR 0;
#define OK 1;
typedef int Status;
typedef int ElemType;
typedef struct Lnode
{
ElemType date;
struct Lnode *next;
}Lnode,*LinList;
Status Getdate (LinList L,int i)
{
LinList q;
int j=1;
q=L->next;
while(q&&j<i)
{
q=q->next;
j++;
}
if(j>i||!q)
return ERROR;
return q->date;
}
Status InsertLin (LinList L,int i,ElemType e)
{
int j=0;
LinList q,p;
q=L;
while(q&&j<i-1)
{
q=q->next;
j++;
}
if(!q||j>i-1)
return ERROR;
p=(LinList)malloc(sizeof(Lnode));
p->date=e;
p->next=q->next;
q->next=p;
return OK;
}
Status DeleteLin (LinList L,int i)
{
int j=0;
LinList q,p;
q=L;
while(q->next&&j<i-1)
{
q=q->next;
j++;
}
if(!(q->next)||j>i-1)
return ERROR;
p=q->next;
q->next=p->next;
free(p);
return OK;
}
Status ShowList(LinList L)
{
LinList q;
int k=0;
q=L->next;
while(q)
{
if(k==1)
cout<<' ';
k=1;
cout<<q->date;
q=q->next;
}
if(k==0)
{
return ERROR;
}
else
{
cout<<endl;
return OK;
}
}
void CreateList(LinList *L,int n)
{
LinList q;
int i;
(*L)=(LinList)malloc(sizeof(Lnode));
(*L)->next=NULL;
for(i=0;i<n;i++)
{
q=(LinList)malloc(sizeof(Lnode));
cin>>q->date;
q->next=(*L)->next;
(*L)->next=q;
}
}
int main()
{
int n,m,i,Date,t,e;
char str[30];
cin>>n;
LinList L;
CreateList(&L,n);
cin>>m;
while(m--)
{
cin>>str;
if(strcmp(str,"get")==0)
{
cin>>i;
Date=Getdate(L,i);
if(Date)
cout<<Date<<endl;
else
cout<<"get fail"<<endl;
}
else if(strcmp(str,"delete")==0)
{
cin>>i;
t=DeleteLin(L,i);
if(t)
cout<<"delete OK"<<endl;
else
cout<<"delete fail"<<endl;
}
else if(strcmp(str,"show")==0)
{
t=ShowList(L);
if(!t)
cout<<"Link list is empty"<<endl;
}
else if(strcmp(str,"insert")==0)
{
cin>>i>>e;
t=InsertLin(L,i,e);
if(t)
cout<<"insert OK"<<endl;
else
cout<<"insert fail"<<endl;
}
}
}
uj5u.com熱心網友回復:
WARNING!!!以下內容不明,后果自負。請勿往下看↓=========================================================================
這是灌水機測驗帖?代碼從哪里拷貝來的,還有亂碼,既然是用標準庫的.h檔案,那么第一句
#include<iostream>
改成
#include<iostream.h>
C++ builder XE 定義_USE_OLD_STL宏無法編譯,oldstl被拋棄了。所有STL均已轉向dinkumware STL實作。參考Embarcadero QC#:91178
戳 ? http://qc.embarcadero.com/wc/qcmain.aspx?d=91178
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/137614.html
標籤:基礎類
上一篇:先用cmake編譯了podofo,并且成功了。但是再用vs2008生成的時候出了好多問題。求大蝦幫助~~
下一篇:c++初學者的疑惑
