数据结构作业

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef struct Node{
   int data;
   struct Node *next;
}Linknode;
void createList(Linknode *&L,int a[],int n){
  Linknode *s;
  L=(Linknode*)malloc(sizeof(Linknode));
  L->next=NULL;
  for(int i=0;i<n;++i)
  {
    s=(Linknode*)malloc(sizeof(Linknode));
    s->data=a[i];
    s->next=L->next;
    L->next=s;
  }
}
void output(Linknode *&L){//输出带头节点的单链表 
  L=L->next; 
  while(L!=NULL){
    cout<<L->data<<endl;
    L=L->next;
  }
}
void revise(Linknode *&L){
  Linknode *p;
  Linknode *s;
  Linknode *temp;
  p=L->next;
  L->next=NULL;
  while(p!=NULL){
    temp=p;//保存p结点 
    p=p->next;
    temp->next=L->next;
    L->next=temp;
  }
}
int main(){
  int a[10];
  for(int i=0;i<10;++i)
  cin>>a[i];
  Linknode *L;
  createList(L,a,10);
  revise(L);
  output(L);
}
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef struct Node{
   int data;
   int freq;
   struct Node *prior;
   struct Node *next;
}Linknode;
void createList(Linknode *&L,int a[],int n){
  Linknode *s;
  L=(Linknode*)malloc(sizeof(Linknode));
  L->next=NULL;
  L->prior=NULL; 
  for(int i=0;i<n;++i)
  {
    s=(Linknode*)malloc(sizeof(Linknode));
    s->data=a[i];
    s->freq=0;
    s->next=L->next;
   	if(L->next!=NULL){
   		L->next->prior=s;
     }
     L->next=s;
     s->prior=L;
  }
}
void output(Linknode *&L){//输出带头节点的单链表 
  L=L->next; 
  while(L!=NULL){
    cout<<L->data<<endl;
    L=L->next;
  }
}
void outputfreq(Linknode *&L){//输出带头节点的单链表 
  L=L->next; 
  while(L!=NULL){
    cout<<L->freq<<endl;
    L=L->next;
  }
}

void LocateNode(Linknode *&h,int x){
  Linknode *p;
  p=h->next;
  while(p!=NULL&&p->data!=x){
    p=p->next;
  }
  if(p==NULL){
    return ;
  }
  p->freq=p->freq+1;//找到并加一
  int freq=p->freq;
  //cout<<p->freq<<endl;
  Linknode *temp=p;//保存该节点为换位置做准备 
  while((freq)>(p->prior->freq)&&p->prior->prior!=NULL){
    p=p->prior;//一直前移到合适的位置 
//		cout<<p->data<<endl;
//		cout<<p->freq<<endl;
//		cout<<p->prior->freq<<endl;
  }
    
  //移动结点 
  //删除该结点 
  Linknode *q=temp->prior;
  q->next=temp->next;
  if(temp->next!=NULL){
  temp->next->prior=q;
  }
  //在p前插入结点temp
  temp->next=p; 
    temp->prior=p->prior;
  if(p->prior!=NULL){
    p->prior->next=temp;
  }
  p->prior=temp;
}
int main(){
  int a[10];
  for(int i=0;i<10;++i)
  cin>>a[i];
  Linknode *L;
  createList(L,a,10);
  LocateNode(L,2);
  output(L);
  
}
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef struct Node{
   int data;
   struct Node *next;
}Linknode;
void createList(Linknode *&L,int a[],int n){
  Linknode *s;
  L=(Linknode*)malloc(sizeof(Linknode));
  L->next=NULL;
  for(int i=0;i<n;++i)
  {
    s=(Linknode*)malloc(sizeof(Linknode));
    s->data=a[i];
    if(L->next==NULL){
    	 s->next=L;
  }else{
   s->next=L->next;
  }
    L->next=s;
  } 
}
void output(Linknode *&L){//输出带头节点的单链表  
  Linknode *temp=L->next;
  while(temp!=L){
    cout<<temp->data<<endl;
    temp=temp->next;
  }
}
void max(Linknode *&L1,Linknode *&L2){
  Linknode *p1=L1->next;
  Linknode *p2=L2->next;
  while(p1->next!=L1){
//		cout<<p1->data<<endl;
    p1=p1->next;
  }
  while(p2->next!=L2){
//		cout<<p2->data<<endl;
    p2=p2->next;
  }
  p1->next=L2->next;
  p2->next=L1;
  p1=L1->next;
    while(p1!=L1){
    cout<<p1->data<<endl;
    p1=p1->next;
  }
}
int main(){
  int a[10];
  for(int i=0;i<10;++i)
  cin>>a[i];
  Linknode *L1;
  createList(L1,a,10);
   Linknode *L2;
  createList(L2,a,10);
//  revise(L1);
//  revise(L2);
  max(L1,L2);
  //output(L1);
}
#include<iostream>
#include<stack>
using namespace std;
  stack<char>s1;
  stack<char>s2;
  stack<char>s3;
bool di11ti(char* str,int n){
  int i=0;
  while(i<n){
    switch(str[i])
    {
      case '{':
        s1.push('{');
        //cout<<1; 
        break;
      case '[':
        s2.push('[');
        break;
      case '(':
        s3.push('(');
        break;
      case '}':
        if(s1.empty()){
          return false;
        }else{
          s1.pop();
        }
        break;
      case ']':
        if(s2.empty()){
          return false;
        }else{
          s2.pop();
        }
        break;
        case ')':
        if(s3.empty()){
          return false;
        }else{
          s3.pop();
        }
        break;
        default:
          cout<<"请输入正确的";
    }
    i++;
  }
  if(!s1.empty()||!s2.empty()||!s3.empty()){
    return false;
  }
  return true;
}
int main()
{

  char x[10];
  for(int i=0;i<10;++i){
    cin>>x[i];
  }
  if(di11ti(x,10)){
    cout<<1;
  }else{
    cout<<0;
  }
}
#include<iostream>
#include<stack>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef struct{
  int data[10000];
  int front,rear;
}SqQueue; 
int MAXSIZE=10000;
void initQueue(SqQueue *&q){
  q=(SqQueue *)malloc(sizeof(SqQueue));
  q->front=q->rear=-1;
}
bool enQueue(SqQueue *&q,int e){
  if((q->rear+1)%MAXSIZE==q->front){
    return false;
  }
  q->rear=(q->rear+1)%MAXSIZE;
  q->data[q->rear]=e;
  cout<<q->data[0]<<endl;
  return true;
}
bool deQueue(SqQueue *&q,int e){
  if(q->rear==q->front){
    return false;
  }
  q->front=(q->front+1)%MAXSIZE;
  e=q->data[q->front];
    cout<<q->data[0]<<endl;
  return true;
}
int main()
{
SqQueue *sq;
initQueue(sq); 
char a;
int b;
while(cin>>a){
  if(a>='A'&&a<='Z'){
    break;
  }else if(a>='1'&&a<='9'){
    enQueue(sq,a-'0');
  }else if(a>='a'&&a<='z'){
    deQueue(sq,b);
  }
}
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值